I have multimodule gradle project each of which contains a number of tests. For each module before running all tests I'd like to perform static fields and other configuration initialization so the tests will be run using this set up. Here is what I mean:
public class MyJUnitConfig{
static {
SomeClass.someStaticIntField = 5;
//...
}
}
The problem is the class won't be initialized and therefore the static initializer won't be called if the class is not used explicitly.
Is there some JUNit (or probably other) annotation to cause class to be initialized upon JVM startup so all the JUnit tests run with the static configuration set up in the MyJUnitConfig static initializer?
You can follow this approach:
@ExtendWith(MockitoExtension.class)(or any annotation that suits you). Create method for static data initialisation and mark it with@BeforeAllannotationThis way you can initialise the static data for all the test classes in the module.