In JUnit 4, you could use @BeforeAll
in a Test Suite and assign a global variable inside the class being called. See below
@SuiteClasses({
PassFail.class
})
public class TestSuiteTest
{
public static TestConfig config = new TestConfig();
@BeforeAll
public static void configure()
{
PassFail.config=config;
}
}
But with JUnit 5, you cannot pass a value to a global variable in the class. If you try, it will be ignored since @BeforeAll
is ignored in @Suite
for JUnit 5. Is there a way to pass a value to a global parameter when used in @Suite
for JUnit 5, similar to how JUnit 4 did? I am using Maven as my build tool. I need a way to do this because I have six different test suites using the same classes but using different values for config
.
Something like this
@Suite
@SelectClasses({
PassFail.class.config = config
})
public class TestSuiteTest {
public static TestConfig config = new TestConfig();
}
Where the config value instantiated in the TestSuiteTest class body is used to assign the global parameter in the PassFail class.