使用Gradle运行特定的仪器单元测试 [英] Running a specific instrumentation unit test with Gradle

查看:66
本文介绍了使用Gradle运行特定的仪器单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Gradle运行特定的Android仪器单元测试?我已经尝试过

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.

推荐答案

使用test.single似乎已被弃用.正确的新方法是

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

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

其中<pattern>可能类似于:

  • com.example.MyTest来运行com.example.MyTest
  • 中的所有测试方法
  • *MyTest以匹配名称以MyTest结尾的每个类中的每个方法
  • *.MyTest.myMethod在任何包中的MyTest类中运行特定的测试方法
  • 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

如果您有多项目构建,请确保在test任务之前给出模块路径;否则,当它在每个子项目中搜索您的测试模式时,您都会收到一个误导性的错误消息.

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.

在Gradle网站上我找不到的任何地方都没有记录.

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

这篇关于使用Gradle运行特定的仪器单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆