vendredi 8 juillet 2016

@RunWith(MockitoJUnitRunner.class) doesn't initialize mocks

I am using Junit 4.8.2. When I run my test class with @RunWith(MockitoJUnitRunner.class) and just annotate mocks with @Mock, it doesn't seem to initialize the mocks. But when I use the static mock() and get rid of the runner and annotations, I can see that the mocks are initialized.

@RunWith(MockitoJUnitRunner.class)
public class MyTestClass
{
    private static final String DOMAIN = "mock";

    @Mock private TransactionManager transactionManager;
    @Mock private SearchManager searchManager;

    private final filter = new Filter(transactionManager,searchManager, DOMAIN);

    @Test
    public void myTest()
    {
        filter.callMethod();      // This throws NPE since transactionManager was null
    }
}

What am I doing wrong here?

Aucun commentaire:

Enregistrer un commentaire