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

2

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(); 

Source

1

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.

1

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoamxoZ2uCdHyOrZ%2BeZaSuvaZ5zKiapKGkpK6vus6tmK2hn6PAbrnOnKJmoaNisaa80Z6amqyVmQ%3D%3D