java 如何从命令行使用 gradle 运行测试套件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30789839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I run a test suite using gradle from the command line
提问by tam
I'm trying to use gradle to run tests with the following command but its not working
我正在尝试使用 gradle 使用以下命令运行测试,但它不起作用
gradle cleanTest test --tests my.package.TestSuite
my test suite looks like the following
我的测试套件如下所示
@RunWith(Suite.class)
@Suite.SuiteClasses({
ATests.class,
BTests.class,
CTests.class
})
public class MySuite {
/* placeholder, use this to contain all integration tests in one spot * */
}
trying to run the following command works, but aggravatingly enough, it runs each test twice. once by itself and then again under the test suite in that same namespace
尝试运行以下命令有效,但更令人恼火的是,它每次测试运行两次。一次单独,然后再次在同一命名空间中的测试套件下
gradle clean test --tests my.package.*
I could just drop the test suite and do it this way but I want to better understand whats going on here and why I can't tell it to directly run the test suite.
我可以放弃测试套件并这样做,但我想更好地了解这里发生了什么以及为什么我不能告诉它直接运行测试套件。
采纳答案by lemoncurd
The following works for me locally.
以下内容在本地适用于我。
gradle -Dtest.single=MySuite clean test
This actually uses a different approach (test inclusion) versus the more advanced filtering approach used by --test
.
这实际上使用了不同的方法(测试包含)与--test
.
As documented in the referenced link, the example above works by creating a file inclusion pattern of the form **/MySuite*.class
whereas --test
attempts to select tests from the scanned test set. I suspect there are some unforseen interactions between the generic test filtering implemented in Gradle and the specific cases around the JUnit Suite runner.
如引用链接中所述,上面的示例通过创建表单的文件包含模式来工作,**/MySuite*.class
同时--test
尝试从扫描的测试集中选择测试。我怀疑在 Gradle 中实现的通用测试过滤与围绕 JUnit Suite 运行程序的特定情况之间存在一些无法预料的交互。
Having said that, even the Gradle docs warn that the above approach is superseded, and in reality I would probably echo @Opal's comment and define an explicit task to run suites for a given phase of testing. For example the following run with gradle clean testSuite
might run an integration suite.
话虽如此,即使 Gradle 文档也警告说上述方法已被取代,实际上我可能会回应@Opal 的评论并定义一个明确的任务来为给定的测试阶段运行套件。例如,下面的 run withgradle clean testSuite
可能会运行一个集成套件。
task testSuite(type: Test) {
include 'MySuite.class'
}
References:
参考: