1

We have a setup where we use Visual Studio 2012 to run our nunit-based unit tests from our local dev environments.

However, we have observed the following pattern:

  1. When running unit tests the first time after Visual Studio has been launched, the tests fail when reading from config-files.

  2. When rerunning the failing unit tests they can read the values from config files just fine.

This is truly a little bit annoying so I was hoping for a bit of help here :-).

I looked at Problem in reading connection string from App.Config when using NUnit 2.5.2 , but since we run our unit tests directly in Visual Studio, there is no way for us to configure NUnit directly.

Community
  • 1
  • 1
Jesper Lund Stocholm
  • 1,973
  • 2
  • 27
  • 49
  • Do you use the standard configuration files (i.e. aplicationname.exe.config) or custom config files - and if so, how do you find the correct location of the files (your application may have been copied to some strange place for the unit tests!)? – Bernhard Hiller Oct 04 '13 at 11:25
  • No custom config files. My test project is of type "Class library" with an added app.config file in it. – Jesper Lund Stocholm Oct 04 '13 at 13:01
  • Just note that if your tests need configuration to run, they are not Unit Tests. They are integration tests. – Spock Oct 07 '13 at 03:40
  • @Raj haha yes - that is true :-). Doesn't make my problem any less annoying, though. – Jesper Lund Stocholm Oct 07 '13 at 06:21
  • Strange I'm using VS2012 Test runner, NUnit 2.6.2.12296, reading an App.config file. No issues. Works every time. Are able to test this with a latest version of NUnit 2.6.2.12296v? Also what happens if you create a new class library with an App.config, are you running to the same issue? – Spock Oct 07 '13 at 08:22
  • i'm having this issue today, running VS2013, NUnit 2.6.2.12296, Resharper 8.2.0.2160 test runner. My config reading is actually occurring in my app, not the units tests. Running the unit test for the standalone project passes. Running all unit tests for solution ( 3 projects), config reading fails – Matt Ritchie Jun 12 '14 at 05:59

1 Answers1

0

NUnit looks for the configuration file in the wrong position, and does not ifnd the config file. Look at

Assembly.GetExecutingAssembly().CodeBase 

and

ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = configFile }, ConfigurationUserLevel.None); 

to get the correct location.

Bernhard Hiller
  • 2,163
  • 2
  • 18
  • 33