您需要在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")
}
此外,關於您的構建問題。 「構建」任務包括一個乾淨的步驟,即從構建目錄清除測試。否則,執行認爲測試已經運行。