devoured elysium
devoured elysium

Reputation: 105227

Is it possible to force Eclipse to recompile my files every time I try to run JUnit tests?

I'd like to know if there's a way to force Eclipse to clear the bin/ folder of the test that's going to be run, and to recompile all the files again?

I'm asking this as my tests involve deleting/renaming/adding files, and that means that at the moment, only the first run of the test will work ok, as from then on the files on which it works are different from what they were in the beginning.

So, what I am asking is not just to recompile again the .java files in the test folder, but basically to do a local "Clean" on the folder where the test is (I don't want a FULL clean/recompilation of the project, as it is huge!).

Thanks

Upvotes: 2

Views: 3946

Answers (1)

ziesemer
ziesemer

Reputation: 28707

To do only a "local clean on the folder where the test is" doesn't seem too likely.

Can't you ensure that all of your files are written to a desired directory - even if to something within File.createTempFile(...) - and then perform a delete on it as part of the beginning of the JUnit test?

Actually, this seems to be exactly what JUnit's TemporaryFolder is for. Details at http://weblogs.java.net/blog/johnsmart/archive/2009/09/29/working-temporary-files-junit-47 . This would also make your build less-specific to Eclipse and work with things like Maven, etc.

Otherwise, just run the test with Ant or Maven - and have it clear out any specific files, folders, or patterns that you need - and then run JUnit. Both of these integrate nicely into Eclipse, and will meet your needs of completing the task before the program to be tested starts - especially if you will be modifying Java class files as well, which you stated.

Upvotes: 1

Related Questions