While writing a simple test which uses launchFragmentInContainer
, I get the following error message:
java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.myapp.appname.debug/androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity (has extras) }
The basic test class is:
class OneFragmentTest {
@Test
fun testOneFragmentState_checkTitleText() {
val args = Bundle().apply {
putString("dummyKey", "dummyValue")
}
launchFragmentInContainer<OneFragment>(args)
onView(withId(R.id.tv_title)).check(matches(withText("title here")))
}
}
I have tried to update AndroidManifest.xml
with the following:
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.myapp.appname" />
but it seems that the tag instrumentation
is valid but the values are written in red, so I assume something is wrong with the targetPackage
and name
.
How can I get rid of this error and run a simple test on OneFragment using launchFragmentInContainer
?