If I use:
androidTestCompile 'com.21buttons:fragment-test-rule:1.0.0'
I get this error when I run the tests:
java.lang.RuntimeException: Could not launch activity
at android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:371)
at android.support.test.rule.ActivityTestRule.launchActivity(ActivityTestRule.java:219)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:268)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1960)
Caused by: java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.prova.provafragmenttestrule/android.support.v4.app.FragmentActivity }
at android.app.Instrumentation.startActivitySync(Instrumentation.java:408)
at android.support.test.runner.MonitoringInstrumentation.access$201(MonitoringInstrumentation.java:90)
at android.support.test.runner.MonitoringInstrumentation$5.call(MonitoringInstrumentation.java:351)
at android.support.test.runner.MonitoringInstrumentation$5.call(MonitoringInstrumentation.java:348)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
To get rid of the error I have to use:
debugCompile 'com.21buttons:fragment-test-rule:1.0.0'
By using debugCompile
(instead of androidTestCompile
) the FragmentActivity
declared in the library's manifest gets packaged into the apk and found.
Is there a way to use the library with androidTestCompile
?
I'm playing with a similar library that allows to test views in isolation, and they have an artifact with the JUnit rule and another one with the Activity + manifest:
https://github.com/novoda/spikes/tree/master/espresso-support#usage
The rule is added with androidTestCompile
and the activity + manifest with debugCompile
, like this:
androidTestCompile 'rule'
debugCompile 'activity + manifest'
Personally, I haven't found a way to use an Activity placed into the androidTest
sourceset without declaring the Activity into the debug
sourceset's manifest. The Activity can live in androidTest
but it always needs to be declared in the debug
manifest to be found.
See this for more info on this:
https://stackoverflow.com/questions/36276909/create-dummyactivity-inside-androidtest-folder-for-testing
https://stackoverflow.com/questions/24451076/android-gradle-espresso-test-not-starting-activity