1
我想創建一個gradle腳本來爲我的.net項目運行xunit測試用例。該腳本看起來像:xunit測試的Gradle腳本什麼都不做或拋出execCommand == null
task xunitTests {
String contents = ""
FileTree tree = fileTree(dir: 'Unit Test',
includes: ['**/bin/Debug/**/[Project]*UnitTest.dll'], exclude:['**/bin/Debug/**/*[Project].dll'])
def reportDir = new File("${buildDir}",'report/xUnit')
tree.each { path ->
if (!executedDll.contains(path.name)) {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'cmd', '/c', 'packages\\xunit.runner.console.2.2.0\\tools\\xunit.console.exe \"$path\" -xml xunit.xml'
standardOutput = stdout
}
executedDll.add(path.name)
println "Output:\n$stdout"
} else {
println "Excluded already executed dll $path.name"
}
}
}
我運行xunitTests任務後輸出我得到的是任務是跟上時代的和構建是成功的,但我沒有看到任何控制檯執行。現在當我執行下面的代碼:
task xunitTests (type:Exec) {
String contents = ""
FileTree tree = fileTree(dir: 'Unit Test',
includes: ['**/bin/Debug/**/[Project]*UnitTest.dll'], exclude:['**/bin/Debug/**/*[Project].dll'])
def reportDir = new File("${buildDir}",'report/xUnit')
tree.each { path ->
if (!executedDll.contains(path.name)) {
def stdout = new ByteArrayOutputStream()
commandLine 'cmd', '/c', 'D:\\LIS\\LIS.Encompass\\packages\\xunit.runner.console.2.2.0\\tools\\xunit.console.exe \"$path\" -xml xunit.xml'
standardOutput = stdout
executedDll.add(path.name)
println "Output:\n$stdout"
} else {
println "Excluded already executed dll $path.name"
}
}
我得到錯誤爲「execCommand == null!」。我在這裏錯過了什麼?我只需要執行測試dll列表來獲取輸出xml。
我試過了你建議的第一個解決方案,但它不起作用。我收到的錯誤是「必須指定至少一個程序集」,並且例外情況是command cmd以非零的退出值3結束。您能幫助我嗎? – jugal
那裏的消息:_必須指定至少一個assembly_完全來自?我想這不是來自'執行'任務。我可能會盡力幫助你,但無法測試我的建議。 – Opal
@jugal這條消息來自這裏:https://github.com/xunit/xunit/blob/master/src/xunit.console/CommandLine.cs#L134,有一些配置丟失.. – Opal