我有以下任务:
def browserList = ["ff", "ie", "ch"];
task testSmoke(type : Test) {
include '**/Smoke.class'
}
此任务正确执行Smoke.class
的测试方法。问题是我想重复使用这个任务。所以我写了下面这段代码:
task createTasks {
browserList.each() {
tasks.create(name: "hello$it", type: Test) << {
include '**/Smoke.class'
}
}
}
在我调用其中一个创建的任务后,例如helloie
或helloff
,项目测试文件夹中的所有测试方法都会被执行(我不知道为什么)。
更新
奥利,这样的事情?
def enviromentList = [
"prod" : "www.prod.sk",
"preprod" : "www.preprod.com",
"test" : "www.test.com"
]
def browserList = [ "ff", "ie" ,"ch"]
task runAll(dependsOn : 'createTasks') {
tasks.findAll { task -> task.name.startsWith('test') }
}
task createTasks {
enviromentList.each() { key, value ->
def enviroment_url = "$value"
def enviroment_name = "$key"
browserList.each {
def browserType = "$it"
println "creating task $key$browserType"
tasks.create(name: "$enviroment_name$browserType", type: Test) {
reports.junitXml.destination = "$buildDir/test-results/$enviroment_name/$browserType/"
reports.html.destination = "$buildDir/test-results/$enviroment_name/$browserType/"
include '**/Smoke.class'
}
}
}
}