views:

80

answers:

3

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 going to 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 way that it will show up as as a choice in "class under test?" Thanks!

P.S. I tried doing a Project/Clean and Project/Rebuild, but it didn't help.

+1  A: 

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.

Zach
When I create it as a class instead of a file, it doesn't end up in the "pass" folder. (It puts it in the src folder for some reason.) How do I get it to create the class in the pass folder?
Bob Jones
@Bob Jones, your `pass` folder has to be a source folder and I'm pretty sure, while creating the new JUnit test class you can specify the destination source folder (`pass` in your case).
Andreas_D
+2  A: 

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
Andreas_D
+1  A: 

Right-Click -> New -> JUnit Test Case

from Java Perspective

Professor_Calculus