vendredi 25 décembre 2015

Android Unit Testing with MockitoJUnitRunner

I am trying to write unit tests for my android project in Android Studio. Following is my sample unit test class.

@RunWith(MockitoJUnitRunner.class)
public class PersistencyTest {

    @Mock
    Context mockContext;

    @Before
    public void setUp() {
        ...
    }

    @After
    public void tearDown() {
        ...
    }

    @Test
    public void test() {
        assertEquals(1, 1);
    }

    @Test
    public void testAddingDocument() {
        assertTrue(true);
    }
}

I am getting the following error :
Test running failed: Test run failed to complete. Expected 4 tests, received 2

When I use AndroidJUnit4.class instead of MockitoJUnitRunner, there is no problem. I guess MockitoJUnitRunner wants every method to be a test method and start with "test" keyword.

What I am doing wrong? Why MockitoJUnitRunner does not recognize @Before and @After annotations?

regards

Aucun commentaire:

Enregistrer un commentaire