Question

Here is my code:

    import org.mockito.Mockito;

    public void testOnPrepareOptionsMenu() {

        Menu aMenu = null;
        DrawerLayout drawerLayoutMock = Mockito.spy(drawerLayout);
        Mockito.when(drawerLayoutMock.isDrawerOpen(Gravity.LEFT)).thenReturn(true);
        boolean menuPrepared = homeViewController.onPrepareOptionsMenu(aMenu);
        assertTrue("Menu shall be prepared", menuPrepared);
        assertNotNull("Menu shall exist", aMenu);

        Mockito.when(drawerLayoutMock.isDrawerOpen(Gravity.LEFT)).thenReturn(false);
        menuPrepared = homeViewController.onPrepareOptionsMenu(aMenu);
        assertFalse("Menu shall not prepared when drawer is closed", menuPrepared);

    }

The test crashes on Mockito.spy(drawerLayout) line.

Was it helpful?

Solution

I forgot to add the following to the libs folder:

http://dexmaker.googlecode.com/files/dexmaker-1.0.jar http://dexmaker.googlecode.com/files/dexmaker-mockito-1.0.jar

Also,I had to add this to the setup() method:

System.setProperty(
            "dexmaker.dexcache",
            getInstrumentation().getTargetContext().getCacheDir().getPath());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top