使用Gradle运行单个集成测试

23

我正在尝试使用Gradle的-Dtest.single标志运行单个集成测试。我已添加另一个源集src/integrationTest并将测试放在其中。我有一个集成测试任务。

task integrationTests(type: Test) {
    dependsOn 'assemble', 'integrationTestClasses'    
    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath
}

这个程序可以正常运行,但如果我试图只运行单个测试,它会告诉我找不到匹配的测试。我不想每次编写新测试时都必须运行所有集成测试。有没有办法解决这个问题?

3个回答

41

从 Gradle 1.10 开始,您可以编写:

 //select specific test method
gradle test --tests org.gradle.SomeTest.someFeature

//select specific test class
gradle test --tests org.gradle.SomeTest

//select all tests from package
gradle test --tests org.gradle.internal*

//select all ui test methods from integration tests by naming convention
gradle test --tests *IntegTest*ui*

//selecting tests from different test tasks
gradle test --tests *UiTest integTest --tests *WebTest*ui

点击此处阅读更多 http://www.gradle.org/docs/1.10/release-notes#executing-specific-tests-from-the-command-line


嵌入的链接和评论都没有提到这是否适用于OP所询问的integrationTest。 - Craig Taylor

24

正确的语法是:

gradle testTaskName -DtestTaskName.single=...

在这种情况下:

gradle integrationTest -DintegrationTest.single=...


当我尝试这样做时,我得到了类似的结果:`$ gradlew -Dtest.single=SingleTest :subproject:test ... :buildSrc:test FAILED FAILURE: Build failed with an exception.出错原因:执行任务':test'失败。 无法找到与模式匹配的测试:SingleTest。` - Noel Yap
也许您没有一个名为该名称的测试类? - Peter Niederwieser
我发现在Linux上使用-Dtest.single='foo'是可以的,但在Windows上由于使用了' vs "或什么都没有而失败了。因此,这些选择可能会受到所使用的shell的影响。 - Petra Kahn
1
实际上,应该是-DintegrationTest.single=...(没有"s")。 - Michał Kosmulski
实际上应该是 -DintegrationTests.single=...,因为他在 Gradle 文件中将任务命名为 'integrationTests'。 - Jacques Koorts

3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接