我試圖排除一個'隔離'文件夾,我設置了硒測試需要更新,我不希望已經運行。我知道一種解決方案是爲這些類中的測試設置和分配測試組,但考慮到這些測試的龐大規模和體積,我寧願使用Ant式過濾器進行測試。從測試中排除一個文件夾與TestNG和Gradle
這裏是我的build.gradle
文件的一個片段:
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
compile "org.seleniumhq.selenium:selenium-java:2.35.0"
compile "org.testng:testng:5.14.10"
testCompile('org.uncommons:reportng:1.1.2') {
exclude group: 'org.testng'
}
testCompile "junit:junit:4.8.2"
compile "com.jayway.restassured:rest-assured:1.8.1"
}
//initialize thread count variable for parallel testing and default to 1
def threadCount = System.getProperty("MAXTHREADS", "1")
tasks.withType(Test) {
maxParallelForks = 1
forkEvery = 1000
ignoreFailures = false
// Pass all system properties to the tests
systemProperties = System.getProperties()
// Makes the standard streams (err and out) visible at console when running tests
testLogging.showStandardStreams = true
exclude '**/tasks/'
exclude '**/disabled/'
classpath += configurations.testCompile
}
task firefox(type: Test) {
maxParallelForks = Integer.valueOf(threadCount) //default is 1 if not specified
testLogging.events "started"
testLogging {
events "started", "passed", "skipped", "failed", "standardOut", "standardError"
exceptionFormat "full" // default is "short"
}
useTestNG() {
excludeGroups 'chrome'
useDefaultListeners = false
listeners << 'org.uncommons.reportng.HTMLReporter'
listeners << 'org.uncommons.reportng.JUnitXMLReporter'
listeners << 'com.xmatters.testng.Listener'
}
testResultsDir = file("${buildDir}/test-results/firefox")
testReportDir = file("${reporting.baseDir}/firefox")
systemProperties.BROWSER = System.getProperty('BROWSER', 'firefox')
exclude '**/selenium/'
exclude '**/setupscripts/'
}
task chrome(type: Test) {
maxParallelForks = Integer.valueOf(threadCount) //default is 1 if not specified
testLogging.events "started"
useTestNG() {
useDefaultListeners = false;
listeners << 'org.uncommons.reportng.HTMLReporter'
listeners << 'org.uncommons.reportng.JUnitXMLReporter'
listeners << 'com.xmatters.testng.Listener'
}
testResultsDir = file("${buildDir}/test-results/chrome")
testReportDir = file("${reporting.baseDir}/chrome")
systemProperties.BROWSER = System.getProperty('BROWSER', 'chrome')
exclude '**/selenium/'
exclude '**/setupscripts/'
}
在線34你可以看到exclude '**/disabled/'
我補充道。這個文件夾是從根文件夾開始的幾個級別。前面的例子與exclude '**/tasks/'
已經在構建文件中,似乎與類似的目錄結構很好地工作。
當我運行構建時,/ disabled /文件夾中的測試仍在運行。有什麼我在這裏做錯了嗎?我假設用這種語法,一個名爲'排除'的目錄將被scanForTestClasses
忽略,這在默認情況下是正確的。任何想法是什麼在這裏?
我在Gradle測試報告中注意到的另一件事是報告中列出的軟件包名稱是default-package
,對於排除在外的測試不是「排除」,而其他要運行的測試列出了正確的包名稱。 Java文件中的包名稱與它們的文件夾結構正確匹配,所以我不確定爲什麼會這樣報告。我檢查過重複,錯別字等,但沒有找到任何地方。
如果有人可以對此有所瞭解,那將會很好,因爲運行這些不完整/損壞的測試類會導致失敗,應該忽略這些失敗,直到這些測試更新。
這些測試正在Linux上運行的我們的測試CI(Jenkins)框中使用Gradle包裝生成的bash腳本運行。