簡體   English   中英

用gradle測試bash腳本

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM