Bart's Blog

Just another WordPress.com weblog

  • Categories

  • Archives

Nunit unit tests passing and failing inconsistently

Posted by bartmaes on March 23, 2010

On one of our C# .NET projects, unit tests were passing and failing inconsistently

  • When running the tests one by one in Visual Studio, all the tests passed
  • When running all the tests in the test class, a specific set of tests failed every time
  • When the tests were running on the CruiseControl build server, those same tests were failing over and over again

Several people have lost some time looking at this problem, e.g. looking whether the dll’s and the configuration files used for the tests were correct. In the end, we found out that one of the tests in the batch was initialising a static variable and that it was never reset to null. Apparently NUnit does not do this for you and you have to do this manually in the [TearDown] part. After we made this change, all tests were passing.

Leave a comment