使用参数gradle通过循环运行一个任务

时间:2014-08-28 08:14:29

标签: eclipse junit gradle

我有以下代码。我想让它与环境和浏览器的所有组合一起运行多次。我不断收到错误,我认为我的结构有问题。

有人可以提供一些有关如何处理此问题的见解吗?

def enviromentList = [ "AZET" : "www.azet.sk", "GOOGLE" : "www.google.com", "IBM" :     "www.ibm.com"]
def browserList = [ "ff", "ie" , "ch" ];

task preTestVerification<< {

enviromentList.each() { key, value -> 
browserList.each() { 


System.setProperty('env.url', '${key}')
System.setProperty('env.name', '${value}')
System.setProperty('env.browser', '${it}')

println "Launch test for enviroment ${key} on url ${value} with ${it} browser" 
tasks.enviromentTest.execute()
//include '**/PreTestVerification.class'

  };
  };

  }

 task enviromentTest(type : Test) {
 include '**/PreTestVerification.class'
 def envBrowser = System.properties['env.browser']
 def envName    = System.properties['env.name']

 reports.junitXml.destination = "$buildDir/test-results/${envName}/${envBrowser}"
 reports.html.destination = "$buildDir/test-results/${envName}/${envBrowser}"

  }

更新

PS C:\KCDev\KCHead\GradleTest> gradle -q runAllTest
33 tests completed, 30 failed
FAILURE: Build failed with an exception.

*出了什么问题:任务执行失败&#39;:helloch&#39;。&gt;有失败的测试。请参阅以下报告:file:/// C:/KCDev/KCHead/GradleTest/build/reports/tests/index.html

  • 尝试: 使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获得更多日志输出。
彼得,我尝试了你的溶剂,这就是结果。

COD

def browserList = [ "ff", "ie" , "ch" ];

task runAllTests << {
println 'running all tests'
}

runAllTests.dependsOn {

browserList.each() { 

tasks.create(name: "hello$it", type: Test) << {

println "hello${it}"
include '**/PreTestVerification.class'

}

}

tasks.findAll { task -> task.name.startsWith('hello') }
}

0 个答案:

没有答案