Using Eclipse to create a new JUnit test case
I have a question about using Eclipse to write an additional JUnit test case for an existing Java application.
There's a folder called "pass" which contains all of the pass tests. I create a new pass test by right clicking on the folder and selecting New → File. However, when I create the JUnit test case, the new test doesn't show up as a choice under the "class under test."
How do I create this test case in the pass folder in such a w开发者_开发知识库ay that it will show up as as a choice in "class under test?" Thanks!
I tried doing a Project/Clean and Project/Rebuild, but it didn't help.
pass
has to be a source folder just like src
. Then, there is a misunderstanding concerning Class under test. This is not the JUnit test class but the class you want to test. Usually you pair a Java class and a JUnit Test Class like this:
Navigator view:
src
com
example
Application.java
test <-- common name for a source folder containing tests
com
example
ApplicationTest.java <-- common name for class containing only tests for
class com.example.Application
Right-Click -> New -> JUnit Test Case
from Java Perspective
When you click on the folder, choose New > Class instead of File (this creates a Java class). Then put your Java code in this class. You can make the individual tests show up by either using the JUnit annotations or by using the "test" prefix on method names.
Then, make sure you rerun your JUNIT configuration (right click on the project and Run As Junit Test) after a rebuild.
精彩评论