Incorrect configuration file when running NUnit tests (TD.NET)

I have a component that reads some configuration from the standard .NET configuration file (app.config).

when I run unit tests (NUnit) for this component (using TD.NET), I noticed that the configuration file is not readable.

After checking AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

I noticed that its value is set to C: \ Users \ ltal \ AppData \ Local \ Temp \ tmp6D2F.tmp (some temporary random localization).

Is there a reason why this is happening? (Is this a NUnit or TD.NET error?)

I believe that I could install this SetupInformation object myself for the test, I have not tried it yet, but still wonder why it is created in this way, and not by default.

+5
source share
2 answers
  • To get around this, you can create app.config in your unit test project. This will then be called instead of the main app.config using your unit tests. You can then change the values ​​in this app.config in your unit tests, making it easier to test different values ​​and configurations, that is, you can configure the app.config test file with specific values ​​before running the test.

    ConfigurationManager.AppSettings[""] = "";

  • Another option would be to place the settings in the Settings.setting file of your main project. Then you do not need to change anything in your unit test project. Some links on the differences between settings and app.config - MSDN Forums , fooobar.com/questions/51847 / ... , User Settings - MSDN

  • , , , app.config , , unit test.

+3

All Articles