How can I run a single test with gradle android

人走茶凉 提交于 2019-12-18 11:17:45

问题


I'm trying to run the tests with this line... but this launches all tests:

./gradlew -DconnectedAndroidTest.single=LandingActivityTests connectedAndroidTest

How can I launch a single test?


回答1:


you can run the single android test in two steps:

  1. ./gradlew installDebugAndroidTest
  2. adb shell am instrument -w -e class com.example.MyInstrumentationTest#testFoo com.example.test/android.support.test.runner.AndroidJUnitRunner
    https://developer.android.com/tools/testing/testing_otheride.html



回答2:


Since Android Gradle plugin version 1.3.0 you can use

./gradlew -Pandroid.testInstrumentationRunnerArguments.class=your.package.LandingActivityTests connectedAndroidTest



回答3:


if you want to run just one test inside the class do something like

./gradlew -Pandroid.testInstrumentationRunnerArguments.class=my.app.package.register.RegisterEmailTest#can_register connectedAndroidTest

can_register is a method in a class RegisterEmailTest

NOTE: the package needs to reference where the class is otherwise it will not work.




回答4:


Visit Testing
Sadly, gradle connectedAndroidTest task is not supporting all the arguments.
There is feature request for gradle team.
If you are using Android Studio, you can create Run Configuration that launches specific test via adb shell am instrument



来源:https://stackoverflow.com/questions/24951421/how-can-i-run-a-single-test-with-gradle-android

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