Unit test class launches old version in eclipse

I have a JUnit test class in my project, which is being updated gradually - I add tests every few weeks and sometimes change the test code.

Surprisingly, when I run the test class using eclipse JUnit Runner 4, it runs my old code (before the upgrade), 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 the only test I just wrote, and got the notorious "Unrooted tests" error without any stack trace to let me know what the problem was.

JUnit debugger response. test7 () is indeed in a compiled test class

I did some research and in accordance with several other topics here, many people have encountered this problem regarding JUnit 3 \ JUnit 4 compatibility, but this is not the case here - I am commenting all my tests using @Test , and I am NOT extending the TestCase class .

Cleaning / building all eclipse projects does not help. However, this problem really works when I mvn clean install my project, but it takes too much time. In addition, renaming the class (Alt + Shift + R in eclipse) causes the new code to run immediately, but renaming it back to the original (and real) name causes the old code to re-run (WTF?)

Help will be appreciated, 10x

+6
source share
2 answers

I managed to solve the problem myself (inspired by a comment made by Harlard). After examining the target directory of my project, I noticed that it does not have test classes that do not contain the binaries of my test. Then I noticed that I missed the classes in src / test / java and put them in a package structure that did not match the package structure of my project, they were direct subdirectories of src / test / java. Therefore, eclipse did not put them in the right place, and the only way to generate binaries for them was to build maven. After refactoring all my test classes in the correct package structure, everything worked perfectly.

0
source

Another solution would be to manually delete the β€œtarget” project folder and rebuild it. This should solve all problems of this kind.

0
source

All Articles