Help, I Broke Nunit – How a Small Duplication in App.Config Can Break Your Tests

Suddenly, NUnit stopped working. We were in the middle of our refactoring, moved code around and ended up with all our tests being ignored. We rebuild the solution – no errors detected. We run our application – no problems at all. We even rebooted the machine. Everything worked except our tests:

There was a little error icon in the test runner and when we clicked on that, it showed us this message:

2018.07.22 20:13:29.669   ERROR System.NullReferenceException: Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object.    at NUnit.Engine.Internal.ServerBase.Start()    at NUnit.Engine.Services.TestAgency.StartService()    at NUnit.Engine.Services.ServiceManager.StartServices()    at NUnit.Engine.TestEngine.Initialize()    at NUnit.Engine.TestEngine.GetRunner(TestPackage package)    at JetBrains.ReSharper.UnitTestRunner.nUnit30.BuiltInNUnitRunner.<>c__DisplayClass5_0.<RunTests>b__0() in C:\Build Agent\work\10c2e82a8ca40a4\Psi.Features\UnitTesting\nUnit\Runner30\Src\BuiltInNUnitRunner.cs:line 89    at JetBrains.ReSharper.UnitTestRunner.nUnit30.BuiltInNUnitRunner.WithExtensiveErrorHandling(IRemoteTaskServer server, Action action) in C:\Build Agent\work\10c2e82a8ca40a4\Psi.Features\UnitTesting\nUnit\Runner30\Src\BuiltInNUnitRunner.cs:line 853  2018.07.22 20:13:29.727    WARN Element TestsForNUnit3.DebtCalculatorTestNew was left pending after its run completion. 2018.07.22 20:13:29.734    WARN Element TestsForNUnit3.DebtCalculatorTestNew.Calculation_can_only_be_called_with_valid_CalculatorMethods was left pending after its run completion. 2018.07.22 20:13:29.735    WARN Element TestsForNUnit3.DebtCalculatorTestNew.Extended_calculation_isnt_allowed was left pending after its run completion. 2018.07.22 20:13:29.735    WARN Element TestsForNUnit3.DebtCalculatorTestNew.Extended_calculation_isnt_allowed_CheckInstanceOf was left pending after its run completion. 2018.07.22 20:13:29.735    WARN Element TestsForNUnit3.DebtCalculatorTestNew.Data_can_be_loaded_from_file_system was left pending after its run completion. 2018.07.22 20:13:29.735    WARN Element TestsForNUnit3.DebtCalculatorTestNew.Something was left pending after its run completion.

The error message didn’t help us much in finding the source of the problem. We had to go the hard way and look at the changes we did since the last commit.

 

The solution

We used Git to show us all changed files and we checked every change we made. It took time, but we found the problem: our App.config got two sections of <appSettings>:

We merged the two sections, removed the no longer needed one and run our tests again. Now they are all green and everything works.

 

Fix the problem, not the symptom

We could have stopped there and continued with writing tests. Instead, we asked our self why this problem happened in the first place. I expected the <appSettings>-section below the connection strings, my team mate at the end. That different set of expectations let us to create a second section and cost us a lot of time.

To prevent this from happening again, we decided to harmonise the order. We had to spend even more time to update all App.config files, but now everything is at the same place and such problems should be a thing of the past.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.