Tuesday, July 7, 2009

Check NUnit test results from .bat script

Problem overview

If you use NUnit you can run the tests using nunit-console utility from your build script. But this test runner just shows the results in console window and saves a report in XML file. There is no functionality which allows to check the results of testing after nunit-console utility execution and perform some actions depending on these results.
Of course there are some powerful build tools which allows to do it, for example NAnt or FinalBuilder. But what should you do if you still use simple .bat files to build your product? The most significant problem: how could you stop build process if some unit test failed?

Proposed solution

CheckTestResults utility helps to solve this issue. It can analize TestResult.xml file produced by nunit-console utility, shows all found failures, sounds a beep for each failure and finally it stops execution and wait for user input if there was at least one failure during testing.

The utility is written on C# and requires .NET 2.0 (or higher) for its work.
Here is its source code:


See full detail: http://www.codeproject.com/KB/dotnet/checknunitresults.aspx