How can I run a single instrumentation test with Gradle Android
Since Android Gradle plugin version 1.3.0 you can use ./gradlew -Pandroid.testInstrumentationRunnerArguments.class=your.package.LandingActivityTests connectedAndroidTest
Since Android Gradle plugin version 1.3.0 you can use ./gradlew -Pandroid.testInstrumentationRunnerArguments.class=your.package.LandingActivityTests connectedAndroidTest
By default your androidTest project will include your app’s R class, but androidTest’s resources will be generated into a separate file. Make sure you import the R class from your test project: import com.your.package.test.R; [..] getInstrumentation().getContext().getResources().openRawResource(R.raw.test_file); You can also directly reference the test project’s R class: getInstrumentation().getContext().getResources().openRawResource(com.your.package.test.R.raw.test_file);
Full disclosure: I am one of Espresso’s authors. Both Espresso and Robotium are instrumentation-based frameworks, meaning they use Android Instrumentation to inspect and interact with Activities under test. At Google, we started out by using Robotium because it was more convenient than stock instrumentation (hats off to Robotium developers for making it so). However, it … Read more