Separate VM for each JUnit Test

I'm running into a problem with some testing some classes that use the java Preferences API. The Preferences API is configured using a System property and is initialized once on first use. Thereafter, each call to get the Preferences object will return the same implementation. Some of my unit tests use one implementation, and some use another implementation, and when I run them all together in IntelliJ (or any other IDE), the later tests fail because they get a Preferences object that they did not expect. Now this is just an example, but there are tons of cases where you want the test environment to be as pristine as possible, and some singleton somewhere screws something up.

I can test in ant because its junit task allows you to fork for each test (as well as some other fork options). Is there any way to do this using intellij's junit plugin (or any other plugin)? Any other workarounds that people have found for this problem?

1 comment

Adam Krieg schrieb:

Now this is just an
example, but there are tons of cases where you want the test
environment to be as pristine as possible, and some singleton
somewhere screws something up.


Singletons are evil, IMHO. :)

I can test in ant because its junit task allows you to fork for each
test (as well as some other fork options). Is there any way to do
this using intellij's junit plugin (or any other plugin)? Any other
workarounds that people have found for this problem?


What about using Mocquer (https://mocquer.dev.java.net/) or something
similar instead of actually using the preferences API in your tests?

cu,
Raffi

--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is nothing like Shakespeare!

herzog@raffael.ch · PGP Key 5D1FF5F4 · http://www.raffael.ch/

0

Please sign in to leave a comment.