I just migrated my project from Spring Boot 2.1 to 2.3 and thus have now JUnit 5 (with vintage) in place (also including mockito-core and mockito-junit-jupiter of version 3.3.3). While all JUnit 4 tests are working fine my first JUnit 5 tests is not working correctly:
@ExtendWith(MockitoExtension.class)
public class SomeTest {
@InjectMocks
private Some to;
@Mock
private SomeProperties properties;
@Test
public void applied() {
....
//properties is null -> NPE
when(properties.getSome()).thenReturn("some");
....
}
The mocks are not injected (NPE in when statement). If i switch to old JUnit 4 style @RunWith(MockitoJUnitRunner.class) all is working fine.
So probably the old runner or vintage runner is used?
How to fix this and get tests with "@ExtendWith" working? I thought i can migrate step by step - let new tests run with junit5 runner.
@Testfor JUnit 5? See also hackernoon.com/mixing-junit4-and-junit5-2da44956de8c for some info on combining JUnit 4 and 5. - Wim Deblauwe