0

My project uses Maven SureFire plugin to run junit tests. A class being tested has some static variables which are set by reading from a config file. Now the problem is that config file is read in multiple tests within the same module, due to which static variables are modified. There is no run time use case where the config file will be read more than once. I am stuck in order to get these tests passed without using Powermock (there are team specific reasons to not use it). Is there a way using maven SureFire plugin or Junit specific annotations by which I can have a separate JVM for running tests in a specific test class?

trailblazer
  • 1,421
  • 5
  • 20
  • 43
  • Can you explain more about why reading the config file more than once is a problem? – Harry Harrison Nov 21 '15 at 12:26
  • Possible duplicate of [How to tell Maven2 to execute jUnit tests one by one each in new JVM instance?](http://stackoverflow.com/questions/6813373/how-to-tell-maven2-to-execute-junit-tests-one-by-one-each-in-new-jvm-instance) - note this question does not specify which version of maven, but even if it's maven3 - the surefire settings shouldn't have changed significantly – Harry Harrison Nov 21 '15 at 12:28
  • Possibly useful: http://stackoverflow.com/questions/26234742/resetting-static-fields-for-junit-tests – Rosa Nov 22 '15 at 23:43
  • @HarryHarrison This is because if different config files are read by different threads, it causes unexpected values for static variables. I think the link you mentioned here will be helpful. I will try this. – trailblazer Nov 23 '15 at 00:16

0 Answers0