您需要在build.gradle中创建测试任务,然后调用这些特定任务来运行特定的一组测试。这里是将筛选出班,使他们没有得到运行两次(运行套件的时候,例如,然后重新运行独立于它的子类)的一个例子:
tasks.withType(Test) {
jvmArgs '-Xms128m', '-Xmx1024m', '-XX:MaxPermSize=128m'
maxParallelForks = 4 // this runs tests parallel if more than one class
testLogging {
exceptionFormat "full"
events "started", "passed", "skipped", "failed", "standardOut", "standardError"
displayGranularity = 0
}
}
task runAllTests(type: Test) {
include '**/AllTests.class'
testReportDir = file("${reporting.baseDir}/AllTests")
testResultsDir = file("${buildDir}/test-results/AllTests")
}
task runSkipSuite(type: Test) {
include '**/Test*.class'
testReportDir = file("${reporting.baseDir}/Tests")
testResultsDir = file("${buildDir}/test-results/Tests")
}
此外,关于您的构建问题。 “构建”任务包括一个干净的步骤,即从构建目录清除测试。否则,执行认为测试已经运行。