MockitoJUnitRunner is deprecated MockitoJUnitRunner is deprecated java java

MockitoJUnitRunner is deprecated


org.mockito.runners.MockitoJUnitRunner is now indeed deprecated, you are supposed to use org.mockito.junit.MockitoJUnitRunner instead. As you can see only the package name has changed, the simple name of the class is still MockitoJUnitRunner.

Excerpt from the javadoc of org.mockito.runners.MockitoJUnitRunner:

Moved to MockitoJUnitRunner, this class will be removed with Mockito 3


You can try this:

@Beforepublic void setup() {    MockitoAnnotations.initMocks(this);}

Because you add @Before annotation, Your mock objects can be new and recorded many times, and in all test you can give objects new properties. But, if you want one time record behavior for mock object please add @BeforeCLass


There is also a @Rule option:

@Rule public MockitoRule rule = MockitoJUnit.rule();

Or in Kotlin:

@get:Rulevar rule = MockitoJUnit.rule()