确定测试厨房测试是否通过或失败

时间:2015-03-24 20:33:48

标签: testing automated-tests chef test-kitchen

我们有一个看起来像这样的脚本:

#!/bin/bash
for cookbook in $cookbooks; do
    cd /path/to/$cookbook
    kitchen test;
    # Log whether the test failed or passed
done;

# Print number of tests passed and number of tests failed

如何确定我的kitchen test是否通过?

1 个答案:

答案 0 :(得分:1)

您可以检查kitchen test命令的退出状态,并增加计数器,如:

#!/bin/bash
let failed=0
let passed=0

for cookbook in $cookbooks; do
  cd /path/to/$cookbook
  kitchen test;

  if [ $? -ne 0 ]
  then
     failed=$((failed + 1))
  else
    passed=$((passed + 1))
  fi
done;

echo "There was $passed passed and $failed failed tests."