MockitoJUnitRunner is deprecated
There is also a @Rule
option:
@Rule
public MockitoRule rule = MockitoJUnit.rule();
Or in Kotlin:
@get:Rule
var rule = MockitoJUnit.rule()
You can try this:
@Before
public 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
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