[英]test a bash script with gradle
我们正在使用gradle作为构建工具以及Java和ansible项目。 现在我也想从gradle中测试bash脚本。
您是否有任何提示/资源,甚至还有示例,说明如何使用gradle测试bash脚本? 如果要测试的bash脚本的返回值为0,或者stdout或stderr包含某些字符串(或不包含它们),则可以简单地执行脚本并获得“ test”通过。
非常感谢您的帮助!
这是一个停止tomcat服务器的Gradle任务示例:
task stopTomcat(type:Exec) {
workingDir '../tomcat/bin'
//on windows:
commandLine 'cmd', '/c', 'stop.bat'
//on linux
commandLine './stop.sh'
//store the output instead of printing to the console:
standardOutput = new ByteArrayOutputStream()
//extension method stopTomcat.output() can be used to obtain the output:
ext.output = {
return standardOutput.toString()
}
}
这也是一个很好的例子,因为其中包含一些有用的指令。
在您的情况下,它将类似于:
task testFile(type:Exec) {
workingDir '/home/user'
commandLine './test.sh'
}
可以在此处找到更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.