Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse doesn't see my new junit test

Tags:

junit

eclipse

I'm using eclipse to run the tests in a single junit(4) test class. The tests in the class all run just fine. Then I add an additional test and run the class through the test running in ecplise again. Only the old tests are run. The new test isn't seen by eclipse. There's no error or anything, it's just as if eclipse is looking at an old version of the test.

If I run the tests using maven, everything works fine. Additionally, after I run the tests in maven, ecplipse can see and run the new test correctly.

Any ideas what's going on? Any ideas how to get ecplipse's test runner to see my new test cases?

like image 202
morgancodes Avatar asked Apr 06 '10 16:04

morgancodes


People also ask

Why Eclipse is not showing as JUnit?

That kind of J icon filled to a "bubble" means that Eclipse doesn't recognize your project as a Java project, and therefore doesn't provide Java options such as Run as JUnit. Try reimporting the project as a Java Project. Save this answer.

How do I update JUnit in Eclipse?

The steps are as below: Project > Properties > Java Build Path > Libraries. Click "Add External JARs..." button at right side --> Select your preferred JUnit jar. Click OK button.

Why is JUnit not working?

The error occurs because the JUnit library has not been configured for the project, but can be resolved using the following steps. 1. Right click on the Java project and select Build Path > Configure Build Path.


4 Answers

I had the same issue. I solved it by doing the following:

  • Going to Project -> Properties -> Java Build Path
    For the source folder src/test/java, the output folder was set to "Default output folder"
  • Setting this to the typical Maven target/test-classes directory in your Maven structure

After this, Maven and Eclipse were in sync (as opposed to Eclipse happily running an older version of the tests, from whenever the last Maven compile was).

like image 143
Ryan Dawe Avatar answered Sep 26 '22 20:09

Ryan Dawe


Maybe you "just" need to create a new Run configuration. Eclipse "remembers" the latest used Run configuration and just repeats it if not told otherwise. To make sure you have a new Run Configuration you can rightclick the test case in the package explorer and choose Run As | Junit Test. Next time you hit play this will be the "remembered" Run configuration etc.

like image 34
benc_cneb Avatar answered Sep 26 '22 20:09

benc_cneb


Possibly src/test is not in the Java Build Path.

Solution on Kepler:

Project -> Build Path -> Configure Build Path -> Source -> Add Folder

Then check the box corresponding to test under src

like image 35
CuongHuyTo Avatar answered Sep 25 '22 20:09

CuongHuyTo


You might find this is likely caused by using Maven to build (Maven usually builds into the 'target' folder), but Eclipse is using a different build folder for its own build process. Simplest way is to go into the target folder under your Eclipse Project (or Bundle if using OSGi) and delete the conflicting subfolders/class-files from under that directory; for me this is my "target" folder. Then get Eclipse to rebuild, and everything should be fine.

Technically, and alternatively, you could just blow away the entire build/target folder if you wanted to, and let Eclipse rebuild everything.

like image 1
Shane Avatar answered Sep 23 '22 20:09

Shane