bash script to find failed tests count in dotnet test

203 views Asked by At

I am trying to get the easiest way to find the count of failed tests using the dotnet test command's flavors. I am running my tests in gitlab and use XUnit.

Basically, the test summary of the dotnet test command gives the output as:

Total tests: 10
     Passed: 7
     Failed: 2
    Skipped: 1
 Total time: 3.0240 Minutes
Test Run Failed.

and I need to capture the value of the Failed test count of 2 in this example.

Any combination of the command with grep or using the test output in a trx file would help.

I tried something like this:

- |
  if [[ -f "$src/testresults/${CI_PIPELINE_ID}_${CI_JOB_ID}.trx" ]]; then
    echo "Test failures observed."
    - if [[ $browser == $skipBrowser ]]; then exit 2; fi
    exit 1
  else
    echo "All tests passed Successfully."
  fi
1

There are 1 answers

0
Barmar On

awk is the simplest way:

failcount=$(command | awk '/Failed:/ {print $2}')