The Type Mockitoannotations. Mock Is Deprecated
I Am Mocking a Object Using @Mock Annotation @Mock Customer Customer; but the @Mock Annotation Is Showing Warning the Type Mockitoannotations. Mock Is...
I am mocking a object using @Mock annotation
@Mock
Customer customer;
but the @Mock annotation is showing warning
The type MockitoAnnotations.Mock is deprecated
and my test case is failed
4 Answers
use
MockitoAnnotations.openMocks(this);
You are using the wrong mock. Try using the below one
org.mockito.Mock instead of org.mockito.MockitoAnnotations.Mock
You may consider removing the deprecated
@BeforeEach
void init() {
MockitoAnnotations.initMocks(this);
}
and replace it with this rule inside the class
@Rule //initMocks
public MockitoRule rule = MockitoJUnit.rule();
I know this is late, but for those who run into this issue today you probably included the wrong dependency. Make sure to add:
testImplementation 'org.powermock:powermock-api-mockito2:2.0.2'
where it's mockito2.