bats - how can i write errors to a log file instead of the general output + run tests in parralel?

505 Views Asked by At
  1. I run a lot of Bats tests in an automated test suite - is there a way to write the failures messages to a separate file??
    when multiple tests fail it is very unclear because of the massive logs. I want the general output to only show "pass/fail" for the tests and the log should contain the errors for each test.

  2. Is there a way to run the tests in parallel to save time?

1

There are 1 best solutions below

3
On

Example code, comments inside:

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 &

This code will produce 5 files on disk.
Output from commands:

$ cat log1
1 some normal log

$ cat log2
0 some normal log

Errors from commands:

$ cat errorlog1
1 some error log

$ cat errorlog2
0 some error log

Main Log file with results:

$ cat mainlog 
Test1 Fail
Test2 Succeed