2016-11-24 40 views
0

我们使用gradle作为构建工具以及我们的java和ansible项目。现在我想从gradle中测试一个bash脚本。使用gradle测试bash脚本

你有任何的窍门/资源或更好的甚至一个例子,我怎么能使用gradle这个测试bash脚本?如果被测试的bash脚本的返回值为0或者stdout或stderr包含某些字符串(或不包含它们),它可以像执行脚本一样简单并具有“测试”通过。

感谢名单了很多提前对您有所帮助!

回答

0

这里有一个摇篮的任务,停止Tomcat服务器的例子:

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' 
} 

更多信息,可以发现here

+0

谢谢你的评论。我知道如何执行命令,但是如何处理bash脚本(或其他程序)的退出代码以使“测试”(而不是构建)失败? – Dominik