0
  1. 我在自动化测试套件中 运行了很多Bats测试 -有没有办法将失败消息写入单独的文件?
    当多个测试失败时,由于大量日志,因此非常不清楚。我希望一般输出只显示测试的“通过/失败”,并且日志应该包含每个测试的错误。

  2. 有没有办法并行运行测试以节省时间?

4

1 回答 1

0

示例代码,里面的注释:

check() {
     #this function emulates your automated test, it has return code, std out, and error out
     echo $1 some error log >&2 
     echo $1 some normal log
     return $1
}

#This two tests are running in parallel in background. 
#Replace 'check 1' with your command to implement.
{ check 1 >> log1 2>>errorlog1 ; 
  RC=$?; 
  [ "$RC" -eq 0 ] \
      && echo Test1 Succeed \
      || echo Test1 Fail
} >>mainlog &

#Replace 'check 0' with your command to implement.
{ check 0 >> log2 2>>errorlog2 ;
  RC=$?;
  [ "$RC" -eq 0 ] \
      && echo Test2 Succeed \
      || echo Test2 Fail
} >> mainlog &

此代码将在磁盘上生成 5 个文件。
命令的输出:

$ cat log1
1 some normal log

$ cat log2
0 some normal log

来自命令的错误:

$ cat errorlog1
1 some error log

$ cat errorlog2
0 some error log

带有结果的主日志文件:

$ cat mainlog 
Test1 Fail
Test2 Succeed
于 2018-05-23T14:02:12.530 回答