MockitoJUnitRunner is deprecated

Albert Hendriks :

I'm trying to make a unit test with @InjectMocks and @Mock.

@RunWith(MockitoJUnitRunner.class)
public class ProblemDefinitionTest {

    @InjectMocks
    ProblemDefinition problemDefinition;

    @Mock
    Matrix matrixMock;    

    @Test
    public void sanityCheck() {
        Assert.assertNotNull(problemDefinition);
        Assert.assertNotNull(matrixMock);
    }
}

When I don't include the @RunWith annotation, the test fails. But

The type MockitoJUnitRunner is deprecated

I'm using Mockito 2.6.9. How should I go about this?

Nicolas Filotto :

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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=423478&siteId=1