Gradle: How to run instrumentation test for class

我与影子孤独终老i 提交于 2019-11-30 08:11:53

As stated in the AndroidTestingBlueprint you can use the android.testInstrumentationRunnerArguments.class property:

./gradlew app:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.android.testing.blueprint.ui.espresso.EspressoTest

According to the docs:

When you run tests from the command-line with Android Debug Bridge (adb), you get more options for choosing the tests to run than with any other method. You can select individual test methods, filter tests according to their annotation, or specify testing options. Since the test run is controlled entirely from a command-line, you can customize your testing with shell scripts in various ways.

To run instrumentation tests with adb for a particular class do:

adb shell am instrument -w -e class 'com.myapp.MyActivityTest' com.myapp.test/android.support.test.runner.AndroidJUnitRunner

Note that if you've defined a custom testInstrumentationRunner on your app/build.gradle file then you need to replace android.support.test.runner.AndroidJUnitRunner with your own, like this:

adb shell am instrument -w -e class 'com.myapp.MyActivityTest' com.myapp.test/com.myapp.MyCustomTestRunner

Tip: If you get an error because the command isn't right, know that you can simply get the right command by running the tests from within Android Studio. You'll see the command on the Run window output.


These 2 documentation pages contain execution options:

https://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner#typical-usage

https://developer.android.com/studio/test/command-line#AMSyntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!