我正在尝试排除我为需要更新的Selenium测试设置的“隔离”文件夹,我不希望运行该文件夹。我知道一种解决方案是为这些类中的测试设置和分配测试组,但是考虑到这里将要进行的测试的绝对大小和数量,我更愿意使用Ant风格的过滤器。
下面是我的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/文件夹中的测试仍在运行。我是不是做错了什么?我假设使用这种语法,名为'exclude‘的目录会被scanForTestClasses忽略,这在默认情况下是正确的。知道这上面是什么吗?
我在Gradle测试报告中注意到的另一件事是,在报告中列出的包名称是default-package,用于不“排除”的排除测试,而其他应该运行的测试列出了正确的包名称。Java文件中的包名与它们的文件夹结构完全匹配,所以我不确定为什么会这样报告。我已经检查了重复项、打字错误等,但没有任何结果。
如果有人能阐明这一点,那就太好了,因为运行这些不完整/损坏的测试类会导致失败,这些失败应该被忽略,直到这些测试被更新。
这些测试是使用Gradle包装器在Linux上运行的测试CI (Jenkins)盒上生成的bash脚本运行的。
发布于 2014-05-06 20:36:43
看起来排除模式应用于文件的相对路径(即相对于根文件夹),这解释了为什么它适用于根文件夹下的文件夹。
使用excludeSpec (请参阅Gradle Test task DSL)应该可以很好地工作:
exclude { it.file.canonicalPath.contains('/disabled/')}当然,请根据您的操作系统注意/ vs \。
https://stackoverflow.com/questions/19646522
复制相似问题