gpt4 book ai didi

unit-testing - 如何使用 Gradle 只运行一个单元测试类

转载 作者:行者123 更新时间:2023-11-28 19:37:48 25 4
gpt4 key购买 nike

我是 Gradle 的新手。我使用 Gradle 1.10 和 Ubuntu 13。

想知道有没有只执行一个单元测试类的命令,类似于testOnly在 SBT 中。

最佳答案

运行单个测试类 Airborn 的答案很好。

使用一些命令行选项,发现here , 你可以简单地做这样的事情。

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 版本开始,它支持选择测试,使用 test filter .例如,

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 的常见用例),check this answer ,因为 --tests 参数将不受支持,您会得到一个错误。

关于unit-testing - 如何使用 Gradle 只运行一个单元测试类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22505533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com