Can you please explain how I can get test coverage? I'm looking for help because Mockito is totally counter-intuitive. If I use only mock objects, then how could I ever get test coverage? I don't understand.
Here are my tests.
package dev.game.adventure; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.CoreMatchers.*; import static org.mockito.Mockito.*; import android.content.Context; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.widget.TextView; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class AdventureTest { private static final String FAKE_STRING = "HELLO WORLD"; @Mock Simulation engine; @Mock AdventureWorld mWorld; @Mock Adventure mworld; @Mock Context aContext; @Mock FullscreenActivity mActivity; @Mock Drawable mDrawable; @Mock Resources mResources; @Mock Place mPlace; @Mock AdventureGame ag; @Test @Ignore public void Tedye() { //when(mWorld.defaultPlace()).thenReturn(mPlace); // myObjectUnderTest.wakeMeAfter(new WalkingPerson(myObjectUnderTest, mWorld, "new", 2, mActivity), 10); //String result2 = myObjectUnderTest.getHelloWorldString(); //assertThat(result2, is(FAKE_STRING));} createPlace("Heaven", target, R.mipmap.dungeon2); // Adventure a = new Adventure(textview, mactivity, ag); } @Test @Ignore public void testd() { // Textview scrollable = ''''''''''''(R.id.textView1); when(mWorld.defaultPlace()).thenReturn(mPlace); Context mCont; } @Test @Ignore public void adventureWorld() { // Simulation myObjecUnderTest = new Simulation(); Adventure a = new Adventure(new TextView(aContext), mActivity, ag); Player p = a.getPlayer(); p.say("foobar", mActivity); p.say("Hello my name is " + a.getPlayer().getMe().name, mActivity); } //@Ignore @Test public void adventureTest() { Simulation myObjectUnderTest = new Simulation(); when(mWorld.defaultPlace()).thenReturn(mPlace); myObjectUnderTest.wakeMeAfter(new WalkingPerson(myObjectUnderTest, mWorld, "new", 2, mActivity), 10); String result2 = myObjectUnderTest.getHelloWorldString(); assertThat(result2, is(FAKE_STRING)); } //@Ignore @Test public void personTest() { Simulation myObjectUnderTest = new Simulation(); when(mResources.getDrawable(R.mipmap.dungeon)).thenReturn(mDrawable); when(mActivity.getResources()).thenReturn(mResources); when(mActivity.getResources().getDrawable(R.mipmap.dungeon)).thenReturn(mDrawable); when(mWorld.defaultPlace()).thenReturn(mPlace); WalkingPerson myObjectUnderTest2 = new WalkingPerson(myObjectUnderTest, mWorld, "blaha", 2, mActivity); String result2 = myObjectUnderTest2.getHelloWorldString(); myObjectUnderTest2.getThings(); myObjectUnderTest2.getWorld(); assertThat(result2, is(FAKE_STRING)); } //@Ignore @Test public void trollTest() { Simulation myObjectUnderTest = new Simulation(); AdventureWorld ag; when(mResources.getDrawable(R.mipmap.dungeon)).thenReturn(mDrawable); when(mActivity.getResources()).thenReturn(mResources); when(mActivity.getResources().getDrawable(R.mipmap.dungeon)).thenReturn(mDrawable); when(mWorld.defaultPlace()).thenReturn(mPlace); WalkingPerson myObjectUnderTest2 = new Troll(myObjectUnderTest, mWorld, "Loki", mActivity); String result2 = myObjectUnderTest2.getHelloWorldString(); myObjectUnderTest2.getThings(); AdventureWorld adv = (AdventureWorld) myObjectUnderTest2.getWorld(); //assertThat(adv.defaultPlace().toString().equals(mWorld.defaultPlace().toString())); // assertThat(adv.defaultPlace(), is(FAKE_STRING)); assertThat(myObjectUnderTest2.getName(), is("Loki")); //assertThat(adv.messsage, is(FAKE_STRING)); } //@Ignore @Test public void cokeTest() { when(mWorld.getPlace("Dungeon")).thenReturn(mPlace); mWorld.getPlace("Dungeon").addThing(new CocaCola("Ljummen cola")); Simulation myObjectUnderTest = new Simulation(); when(mResources.getDrawable(R.mipmap.dungeon)).thenReturn(mDrawable); when(mActivity.getResources()).thenReturn(mResources); when(mActivity.getResources().getDrawable(R.mipmap.dungeon)).thenReturn(mDrawable); when(mWorld.defaultPlace()).thenReturn(mPlace); WalkingPerson myObjectUnderTest2 = new Troll(myObjectUnderTest, mWorld, "blaha", mActivity); String result2 = myObjectUnderTest2.getHelloWorldString(); myObjectUnderTest2.getThings(); myObjectUnderTest2.getWorld(); assertThat(result2, is(FAKE_STRING)); } @Ignore @Test public void testPlace() { Simulation myObjectUnderTest = new Simulation(); when(mResources.getDrawable(R.mipmap.dungeon)).thenReturn(mDrawable); mWorld.createPlace("Heaven", mActivity, R.mipmap.dungeon2); mWorld.createPlace("Hell", mActivity, R.mipmap.dungeon2); mWorld.connect("Heaven", "Hell", "Down", "Up"); mWorld.randomPlace(); assertTrue(false); } @Ignore @Test public void useAppContext() throws Exception { // Context of the app under test. // Context appContext = InstrumentationRegistry.getTargetContext(); // assertEquals("dev.game.adventure", appContext.getPackageName()); } } The repository is available online.

something()method on aWhateverclass that could return aFrobozzinstance that contains noSwotobjects, but you cannot readily create aWhateverthat will do this (as it only occurs in the rain on leap days). So, you create a mockWhateverthat hassomething()return this specific result for a test, and you testWhatevernormally otherwise.ContextorTextViewto use. So, you mock those, so your own test code (and production code) can run on the JVM, while interacting with the mocks. You aren't trying for test coverage ofContext, as you did not writeContext. You are using a mockContextto test other code that happens to use aContext.