3

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: ...

BradLaney
  • 2,384
  • 1
  • 19
  • 28

1 Answers1

3

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.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
  • How were you able to reproduce it? I tried reproducing in a blank solution and was unable to. – BradLaney Jul 19 '11 at 15:44
  • I've asked Test Runner devs to look into it and they have replied that the "no tests found" issue has been reproduced. We'll reply with the details once the issue's status is changed. – Alex Skorkin Jul 19 '11 at 17:40
  • Here is some additional information about this issue. When CodeRush Unit Test Runner runs tests, it sets the Directory.CurrentDirectory value to TestAssemblyPath that is detected as Path.GetDirectoryName(TestAssembly). NUnit SettingsService tries to get file name settings from ConfigurationManager.AppSettings["SettingsFile"]. Thus, if TestAssemblyPath contains the .config file (e.g. as it is shown below): – Alex Skorkin Jul 21 '11 at 10:46
  • NUnit SettingsService gets settings from "[SettingsFileDirectory]\Settings.settings" and fails because this content is invalid. Now we have excluded the NUnit SettingsService initialization as it hasn't influenced the functionality of CodeRush Unit Test Runner. – Alex Skorkin Jul 21 '11 at 10:47
  • Hey, I got the patch you sent out, but it didn't fix anything. Same ol' same ol' – BradLaney Jul 25 '11 at 16:33
  • I apologize but I didn't send the patch. Have you asked for that from support? What is the version of the patch? - they might have sent you the incorrect one. – Alex Skorkin Jul 25 '11 at 20:19
  • I received an email telling me to go download the newest published version. Maybe this is unrelated? It was on 7/21 and it told me there was a maintenance release and I should download it straight from the site. I looked into the code and have no idea how this can be fixed. I think I just need to use a different config value. – BradLaney Jul 25 '11 at 23:30
  • #if NET_2_0 string settingsFile = System.Configuration.ConfigurationManager.AppSettings["settingsFile"]; #else string settingsFile = System.Configuration.ConfigurationSettings.AppSettings["settingsFile"]; #endif – BradLaney Jul 25 '11 at 23:30
  • Okay I looked into it deeper. I ran process monitor for my .config file. It seems that there is a CR_ExtUnitTestRunnerNet4.exe that is incorrectly reading my file. I think its trying to load the file like NUnit does. But NUnit only looks for "NUnitSettings.xml". Path.Combine( NUnitConfiguration.ApplicationDirectory, settingsFileName ); – BradLaney Jul 25 '11 at 23:52
  • That build doesn't contain the fix for the issue, please request a build containing the fix from this link (http://www.devexpress.com/issue=B187269) clicking the "Request Fix" button. Hope this will help. – Alex Skorkin Jul 26 '11 at 09:59