Search code examples
visual-studioconfigurationnunitcoderush

NUnit running in visual studio with coderush or testdriven.net "no tests found"


My company has been using MSTest and NUnit. I am now switching us over to only use NUnit. The code is riddled with architectural problems, so we can just ignore those and work on how to get it to actually work. The main issue, I guess, is that the settings for the database connection is pulled straight from ConfigurationManager.AppSettings[]. In this case its the "SettingsFile" path. It is a path to our master configuration file.

The reason I bring that up, is because when that "SettingsFile" exists, NUnit errors, if I name it SettingsFile2 it does not error. I also rename the references to it in my code, so it still works, it just doesn't error anymore.

When NUnit throws the error it returns no tests found.

I thought that maybe "SettingsFile" is some reserved appSetting for NUnit, as rediculous as it sounds, but I found nothing referring to such.

I also created a completely blank project. Added a testing C# test template project, added an nunit test, added an app.config, tested that and it worked. I even had the same app.config settings.

Just to reiterate: If I go into the app.config for the test project, and change key="SettingsFile" to key="SettingsFile2" and then change my configuration class to be ConfigurationManager.AppSettings["SettingsFile2"] and change nothing else, it will now build correctly. Why is this happening?

I know the solution would be to not use the word "SettingsFile" in the appSettings... but it already does in all of our production servers, test servers, staging servers, dev servers, etc. We do not have an easy way to update them all, but if we have too, I just have to argue my point to the managers.

Output from DXCore test:

Testing started:

Exception:
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
StackTrace:
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at CR_ExtUnitTestRunner.Invoker.InvokeInThread()
InnerException:
Exception:
Message: Error loading settings file
Source: nunit.util
StackTrace:
   at NUnit.Util.XmlSettingsStorage.LoadSettings()
   at NUnit.Util.SettingsService..ctor(Boolean writeable)
   at NUnit.Util.SettingsService..ctor()
   at CR_NUnitTesting.Executor.Initialize()
   at CR_NUnitTesting.Executor.Execute(ExecuteTestData data)
   at CR_NUnitTesting.NUnitExtension.Execute(Int32 major, Int32 minor, ExecuteTestData data)
   at CR_NUnitTesting.NUnitExtension.<InitializePlugIn>b__2(ExecuteTestData data)
InnerException:
Exception:
Message: Object reference not set to an instance of an object.
Source: nunit.util
StackTrace:
   at NUnit.Util.XmlSettingsStorage.LoadSettings()
No tests found.
Duration : 5.25776431101399

UPDATE:

Adding a reference to our CORE project causes the issue. The core project is the project that reads the SettingsFile attribute. Note that I put IO file write before anything accesses SettingsFile, and nothing was logged. I searched for static class constructors in the CORE project. There are none. I have no idea why adding a reference would break this.

UPDATE:

The Unit Test Runner in coderush does not update to show the correct tests. I changed the config settings to "SettingsFile2" so the test runs fine, and then the Unit Test Runner updates correctly. But as soon as I right clicked on a test, and said go to test, it now shows all tests that have ever existed, which are now deleted.

Another thing thats odd: Coderush is printing out the results twice, but only running the test once.

Searching for tests... Total tests: 2, filtered: 1

CanConfirmDatabaseMatchesMappings has failed: ... CanConfirmDatabaseMatchesMappings has failed: ...


Solution

  • We (DevExpress) have reproduced the issue and registered it in our database. The fix for the CodeRush Unit Test Runner is almost ready. Once the status of the bug is changed, you are welcome to request a daily build containing the fix from the issue's page.