如何在Gradle上仅运行一个本地测试类 [英] How to run only one local test class on Gradle
问题描述
我是Gradle的新手.我使用Gradle 1.10和Ubuntu13.
I am new to Gradle. I use Gradle 1.10 and Ubuntu 13.
我想知道是否有命令仅执行一个 local 测试类,类似于SBT中的"testonly".
I want to know if there's any command to execute only one local 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的常见用例),选中此答案,作为
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上仅运行一个本地测试类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!