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

查看:33
本文介绍了使用 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>

其中 可能类似于:

  • 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天全站免登陆