Please pay attention to the following points:
Are you using @org.mockito.InjectMocks
?
JUnit version:
2.1) If it’s JUnit 4, configure the test class as follows:
@org.junit.Before
public void setUp() {
org.mockito.MockitoAnnotations.openMocks(this);
}
2.2) If it’s JUnit 5:
@org.junit.BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}
In my case, I am not using @ExtendWith(MockitoExtension.class)
in the class.