I've run into this problem where NUnit tests aren't executed by Resharper's test runner. After a git bisect
session I've isolated the commit that causes this, but I can't pin down why; most of the solutions I find refer to corrupt app.config
files, but my commit only changed C# code. It only fails for one of my test projects - the unit tests - while other tests (integration and acceptance tests, also driven by NUnit) run fine.
So, I've tried to troubleshoot other ways, and following this guy's troubleshooting, I installed the NUnit Test Adapter for Visual Studio to try to run the tests with VS instead of R#.
Now, re-building the entire solution and checking the Test Output window, I see the following:
NUnit 1.2.0.0 discovering tests is started
Exception System.ArgumentNullException, Exception thrown discovering tests in D:\Code\ThisProject\src\MainWebApplication\bin\MainWebApplication.dll
Exception System.ArgumentNullException, Exception thrown discovering tests in D:\Code\ThisProject\src\UnitTests\bin\Debug\UnitTests.dll
NUnit 1.2.0.0 discovering test is finished
Hm... I did introduce a new method in this commit, that throws argument null exceptions. I wonder what happens if I comment out those checks?
NUnit 1.2.0.0 discovering tests is started
Exception System.ArgumentNullException, Exception thrown discovering tests in D:\Code\ThisProject\src\MainWebApplication\bin\MainWebApplication.dll
NUnit 1.2.0.0 discovering test is finished
A test with the same name 'UnitTests.SomeNamespace.SomeTestClass.SomeTestMethod(someparameter)' already exists. This test is not added to the test window.
Wait, what?
Removing an argument null check in my code, which is in a library assembly (i.e. in neither of the assemblies that initially failed, although both of them call into this method) made test discover perform (slightly) better. What is going on?
But it gets weirder still:
After having seen the above oddness, I resumed R# (which I had suspended as part of troubleshooting) and tried to run the tests again. They all run, and passed. Yes, I double checked and uncommented the null checks (changing nothing else) and I'm back to square one - Inconclusive: test wasn't run
, for every single test in the assembly.
What is going on here?
I have no idea of how it could be relevant, but there are a couple of "exceptional" things about the particular method with the null checks, so I figure I can't leave them out of a question like this (where, to my knowledge, everything including Mickey Mouse could be relevant...):
The method is often called with one of the parameters filled by a service location call (bad practice, I know, but it's a huge project with legacy code, and the calls are littered all over; there's no way to change that). If a call is made like that and the IoC container hasn't been setup, the argument will indeed be null.
The method calls out to
HttpContext.GetGlobalResourceObject
, passing the arguments on (which is why I want a null check in the first place...), and we've configured a custom resource provider throughweb.config
. I haven't changed any of this configuration, just moved the call to a different place.