问题描述
我是 Gradle 的新手.我使用 Gradle 1.10 和 Ubuntu 13.
I am new to Gradle. I use Gradle 1.10 and Ubuntu 13.
我想知道是否有任何命令可以只执行一个单元测试类,类似于testOnly
在 SBT 中.
I want to know if there's any command to execute only one unit test class, similar to testOnly
in SBT.
推荐答案
运行单个测试类 Airborn 的回答很好.
To run a single test class Airborn's answer is good.
使用一些命令行选项,在此处,您可以简单地做这样的事情.
With using some command line options, which found here, you can simply do something like this.
gradle test --tests org.gradle.SomeTest.someSpecificFeature
gradle test --tests *SomeTest.someSpecificFeature
gradle test --tests *SomeSpecificTest
gradle test --tests all.in.specific.package*
gradle test --tests *IntegTest
gradle test --tests *IntegTest*ui*
gradle test --tests *IntegTest.singleMethod
gradle someTestTask --tests *UiTest someOtherTestTask --tests *WebTest*ui
从 gradle 1.10 版开始,它支持选择测试,使用 测试过滤器.例如,
From version 1.10 of gradle it supports selecting tests, using a test filter. For example,
apply plugin: 'java'
test {
filter {
//specific test method
includeTestsMatching "org.gradle.SomeTest.someSpecificFeature"
//specific test method, use wildcard for packages
includeTestsMatching "*SomeTest.someSpecificFeature"
//specific test class
includeTestsMatching "org.gradle.SomeTest"
//specific test class, wildcard for packages
includeTestsMatching "*.SomeTest"
//all classes in package, recursively
includeTestsMatching "com.gradle.tooling.*"
//all integration tests, by naming convention
includeTestsMatching "*IntegTest"
//only ui tests from integration tests, by some naming convention
includeTestsMatching "*IntegTest*ui"
}
}
对于多口味环境(Android 的常见用例),检查此答案,作为--tests
参数将不受支持,您将收到错误消息.
For multi-flavor environments (a common use-case for Android), check this answer, as the --tests
argument will be unsupported and you'll get an error.
这篇关于如何使用 Gradle 只运行一个单元测试类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!