I've just set up Roboelectric 3.2.2 with a new app and I have written my first simple test:
@RunWith(RobolectricTestRunner.class)
@Config(manifest="src/main/AndroidManifest.xml",
packageName="my.pacakge.name.debug")
public class MainActivityTest {
@Test
public void clickButton() {
MainActivity mainActivity = Robolectric.setupActivity(MainActivity.class);
String text = ((TextView)mainActivity.findViewById(R.id.text_main)).getText().toString();
assertEquals("Should equal Hello World!", "Hello World!", text);
}
}
I've followed all the set up and instructions here and here but I am still getting this error every time I try to run the test:
android.content.res.Resources$NotFoundException: Unable to find resource ID #0x0 in packages [android, my.package.name.debug]
This exception occurs at the first line of the test where I am calling setupActivity()
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…