Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit test class runs old version in eclipse

I have a JUnit test class in my project which is updated incrementally - I add tests every few weeks and sometimes modify the tests' code.

Surprisingly, when I run the test class using eclipse JUnit Runner 4, it runs my old code (before the update) and not the new one. I can change the code, add or remove tests but it still runs the old code.

I tried to isolate the problem and run a single test that I've just written and got the infamous "Unrooted tests" error without any stack trace to give me a clue what the problem is.

JUnit runner response. test7() is indeed within the compiled test class

I did some research and according to a few other threads here, many people encountered this problem with regards to JUnit 3 \ JUnit 4 compatibility, but this is not the case here - I annotate all my tests with @Test and I do NOT extends the TestCase class.

Cleaning / Building all eclipse projects doesn't help. However, this problem does work itself around when I mvn clean install my project, but this takes too much time. Also, renaming the class (Alt+Shift+R in eclipse) gets the new code to run immediately, but renaming it back to its original (and valid) name, gets the old code to run again (WTF?)

Help would be appreciated, 10x

like image 693
KidCrippler Avatar asked Apr 03 '16 11:04

KidCrippler


2 Answers

I managed to solve the problem on my own (inspired by a comment contributed by Harlard). After examining the target directory of my project, I noticed that the test-classes dir inside it doesn't include the binaries of my test. I then noticed that I misplaced the classes within src/test/java and put them in a package structure that doesn't conform to the package structure of my project, they were direct sub-directories of src/test/java. Therefore, eclipse didn't put them in the correct place and the only way to generate binaries for them was by executing a maven build. After refactoring all my test classes to the correct package structure, everything worked perfectly.

like image 120
KidCrippler Avatar answered Oct 04 '22 19:10

KidCrippler


I had the same issue. It was due to a defective .classpath. Removing this .classpath and re-importing the project, generates a correct .classpath and fixed the environment.

like image 42
scoulomb Avatar answered Oct 04 '22 18:10

scoulomb