Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

android - Running a specific instrumentation unit test with Gradle

Is there a way to run a specific Android instrumentation unit test using Gradle? I've tried

gradle -Dtest.single=UnitTestName connectedInstrumentTest

but it seems to run all the tests in the package.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Using test.single appears to be deprecated. The new correct way to do this is

./gradlew :<module>:test --tests <pattern>

where <pattern> could be something like:

  • com.example.MyTest to run all test methods in com.example.MyTest
  • *MyTest to match every method in every class whose name ends with MyTest
  • *.MyTest.myMethod to run a specific test method in class MyTest in any package

If you have a multi-project build, make sure to give the module path before the test task; otherwise you'll get a misleading error message when it searches for your test pattern in every subproject.

None of this is documented on the Gradle site anywhere I could find it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...