Search code examples
c#powershellautomated-testsnunitcakebuild

Rerun Failed Test Cases with Cake and NUnit


I am using a cake script to run test cases with NUnit. The cases are written in C#. How can I tell the script to rerun failed test cases? I am also using PowerShell to bootstrap the cake build.


Solution

  • NUnit currently doesn't have an out-of-the-box feature to re-run failed tests. You'll have to:

    1. Compile a list of failed tests, either by extracting the failed tests from the Test Result XML file, or by writing the failed tests to a file by implementing a custom IResultWriter.

    2. Run NUnit giving it the list of tests to execute (the failed tests you got on step 1), using --test=FULLNAMES or --testlist=FILE as described in the documentation.

    --test=FULLNAMES Comma-separated list of FULLNAMES of tests to run or explore. This option may be repeated. Note that this option is retained for backward compatibility. The --where option can now be used instead.

    --testlist=FILE The name (or path) of a FILE containing a list of tests to run or explore, one per line.

    If you're using the NUnit3Runner for Cake, you can configure the NUnit3Settings with the tests to be run (Test or TestList).