Reputation: 25265
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?
Upvotes: 17
Views: 29608
Reputation: 1038
I added this to my .classpath in the project's home directory.
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Upvotes: 0
Reputation: 2897
It means that you have created a Test class that you haven´t build yet. After a build, for example with "gradle build" the Test class will be found by Eclipse too. In my case I had to make a cleanup before as well.
Upvotes: 0
Reputation: 616
Here is how i fixed my problem...
Note: this assumes your project's default output folder for tests is target/test-classes, if it is not then adjust accordingly. Also, make sure you have the right JUnit version selected under the JUnit Run Configuration as well and your src/test/java directory is a source folder to your project, etc. as mentioned by others.
Upvotes: 0
Reputation: 1
Add "test" in front of your test classes if not there already the @Test annotation isn't always picked up from Eclipse's Junit Test framework.
Upvotes: 0
Reputation: 907
In response to the answer provided by Ryan Dawe, I have found out that Default output folder can be set to only one folder, for all the source folders on build path. So if i changed the output folder to target/test-classes, my src/main/java was also outputting classes there. You might have written this response for a different older version of eclipse, but as of Mars.2 release, we can only have one default output folder for all source folders.
The best solution i have found so far for this problem is to just include the target/test-classes as a class folder, by going to Project -> Properties -> Java Build Path -> Libraries -> Add Class folder.
Upvotes: 1
Reputation: 11
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.
Upvotes: 1
Reputation: 1333
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
Upvotes: 2
Reputation: 99
I had the same issue. I solved it by doing the following:
src/test/java
, the output folder was set to
"Default output folder"target/test-classes
directory in your Maven structureAfter 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).
Upvotes: 9
Reputation: 101
This seems to be the same issue as junit not using the newest file
The problem seems to be that Eclipse puts the compiled tests in the wrong folder which can be solved by manually specifying where they should end up.
Upvotes: 0
Reputation: 31
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.
Upvotes: 1
Reputation: 68982
It seems that your project wasn't recompiled. Either check Menu:Project/Build Automatically or do it manually as Boris Pavlocic commented.
Upvotes: 0