3

I have a JUnit (4) test class that uses Static variables and mocking. The static variables are being set prior to running. (Please see below as to why) However, when I run the test case, the variable are being reset to NULL. Does anyone have an explanation for this? This appears to happen after powermock has been instantiated.

My Theory

My theory is that the PowerMock creates a new Java environment inside the new Java environment so that it can isolate the mocked class redirection. I believe that this behavior started in the recent change to adding PowerMock to my application. However, I'm not sure if there is an alternative to using Static variables to accomplish the goal of the class. (Other than a dynamic class creation, which would be a little unmaintainable).

Why am I setting static variables in the test case?

I'm doing this as that this is the best that I know to set a particular setting into the test at runtime, without resorting to files. JUnitCore::run takes in the class object, but it cannot take in an initialized version of the class.

monksy
  • 14,156
  • 17
  • 75
  • 124
  • http://stackoverflow.com/a/11955737/337621 this seems to be your problem – Gábor Lipták Sep 18 '14 at 19:55
  • I'm not trying to mock a static class... I'm trying to keep the static members that are already defined in the test. The mocking going on is a deep dependency. – monksy Sep 18 '14 at 20:12

0 Answers0