How can I have JUnit use a separate ClassLoader
for each test class it executes?
I am writing a JUnit TestRunner
for a library that sets a lot of static variables. I essentially want to reset all of these between each test class, without needing to know what all of them are. I do not want to be coupled to intimate knowledge of the framework, as whenever the library changes internally then my TestRunner
will break.
Before I go any further, I want to make absolutely clear that I really do want to do this.
- I do not have control over the library.
- I do not have the option of not using static variables.
- I do not want to use reflection or Powermock, as I don't want to know what's going on in the library.
- I do not want to use Maven config to fork testing processes, as then the testing utility is tied to a build tool.
Every other answer I can find on StackOverflow just says "don't do that," which isn't helpful. First person to answer with "static variables are dumb" wins a doughnut.