Bash bats—如何将错误写入日志文件而不是常规输出+;在parralel中运行测试?

Bash bats—如何将错误写入日志文件而不是常规输出+;在parralel中运行测试?,bash,automation,bats-core,Bash,Automation,Bats Core,我在自动化测试套件中运行了很多测试- 有没有办法将故障消息写入一个单独的文件?? 当多个测试失败时,由于大量日志,这一点非常不清楚。 我希望常规输出只显示测试的“通过/失败”,并且日志应该包含每个测试的错误 有没有办法并行运行测试以节省时间 示例代码,内部注释: check() { #this function emulates your automated test, it has return code, std out, and error out echo $1

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

  • 有没有办法并行运行测试以节省时间


  • 示例代码,内部注释:

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

    我如何实现这一点?check函数的作用是什么?为了运行测试,我需要使用@test注释,而您的示例没有测试。亲爱的@Nir,测试函数模拟您的自动测试,它有返回代码、std out和error out。因此,您需要用运行测试的命令名替换
    check 1
    check 0
    。这看起来像是通用的bash代码。我认为他建议您实现自己的测试框架,而不是处理BAT中的坏日志记录。