mock instance is null after @Mock annotation

Tags: , , , ,

I try to run this test:

    @Mock IRoutingObjHttpClient routingClientMock;
    @Mock IRoutingResponseRepository routingResponseRepositoryMock;

    public void testSendRoutingRequest() throws Exception {
        CompleteRoutingResponse completeRoutingResponse = new CompleteRoutingResponse();
        completeRoutingResponse.regression_latencyMillis = 500L;


        RoutingObjHttpClientWithReRun routingObjHttpClientWithReRun = new RoutingObjHttpClientWithReRun
                (routingClientMock, routingResponseRepositoryMock);


but I get NullPointerException for:


what am i missing?


When you want to use the @Mock annotation you should use the MockitoJUnitRunner

public class MockitoTest {

    private IRoutingObjHttpClient routingClientMock;

    public void testSendRoutingRequest() throws Exception {
        // ...


See also this tutorial.

Source: stackoverflow