Java/Eclipse: How to configure Run Configuration's Classpath for JUnit test?

前端 未结 2 1450
轮回少年
轮回少年 2020-12-15 14:34

I have an Eclipse project with the following directory structure:

MyProj/
    src/main/java/
        com.me.myproject.widgets
            Widget.java
    src         


        
2条回答
  •  爱一瞬间的悲伤
    2020-12-15 15:25

    If your WidgetTest class is written as a JUnit test, eclipse will try to run it as a Junit test automatically. If it doesn't, you should right click on the class in the package explorer, choose Run As >> Run Configuration >> choose Junit

    To run a Junit test:

    • in JUnit3, the class should implement TestCase and all the method names should start "test"

    • in JUnit4, all the methods should be preceded by a @Test annotation

    To place that config file in the classpath: when setting the Run Configuration as above, go to the Arguments tab in the upper right pane and in the VM arguments specify the classpath:

       -cp .:/path/to/the/config/file 
    

    However, if that file is in a package in the source directory, it should automatically be included in the classpath.

提交回复
热议问题