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()
.
Robolectric
do you use? I would advise to use latest and remove robolectric gradle plugin as well remove manifest and package name specification fromConfig
– Uniat