Dave
Dave

Reputation: 19340

How can I get Eclipse to re-compile my JUnit test when I make a change to it?

I'm using Eclipse Juno on Mac 10.7.5, Java 6, Junit 4.8.1, and Maven 3.0.3. I have imported a Maven project into Eclipse but am having trouble getting JUnit test compilations to refresh. When I edit a JUnit test in the editor, save it, right click on the test and select "Run As" -> "JUnit Test," Eclipse doesn't appear to be recompiling the test, rather using the original class file in my target/test-classes directory. When I compile on the command line using "mvn clean test-compile," the updated class appears correctly in the target/test-classes directory.

So my question is, how can I get Eclipse to properly compile my test and place it in the target/test-classes directory? I have verified in my project settings that under "Source," I have myproject/src/test/java with the output folder as myproject/target/test-classes with Included (All) and excluded (None).

Upvotes: 3

Views: 3599

Answers (1)

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28757

This is strange. JUnit tests are treated just like any other Java file and they should be recompiled on save. First, make sure that Project -> Build automatically is enabled.

If yes, then go to the file system, delete the class file for your test and then make a whitespace change to the file from inside the IDE. Is the file regenerated? My guess is that it is.

If not, then take a look at your error log and paste any relevant errors here.

Upvotes: 3

Related Questions