@TestParameter fields are only injected when the test class is run with
@RunWith(TestParameterInjector.class). If the test class uses another runner
such as @RunWith(JUnit4.class), JUnit does not initialize @TestParameter
fields, leaving them at their default Java values (null, 0, or false).
@RunWith(JUnit4.class)
public final class MyTest {
@TestParameter boolean enabled;
@Test
public void myTest() {
// `enabled` is always `false`!
}
}
@RunWith(TestParameterInjector.class)
public final class MyTest {
@TestParameter boolean enabled;
@Test
public void myTest() {
// Runs with `enabled = true` and `enabled = false`.
}
}
Suppress false positives by adding the suppression annotation @SuppressWarnings("TestParametersNotInitialized") to the enclosing element.