1

I have written some nunit tests and within my test folder and even at the root project dir I have tried link an app.config file to my test code but it never picks up and says cannot have a null value I.e the string I would like pull into my code is not picked up Can you help?

Pretty standard stuff really as you can see.

In app config,

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <ApplicationSettings>
       <add key="name" value="Configuration Example Project"/>
   </ApplicationSettings>
</configuration>

And within my code,

   string data1 = ConfigurationManager.AppSettings["name"];

Btw I do have system.configuration added

So far I have tried moving the app.config file in root dir,test dir, changed name to project name, none of them worked.

As this is the most up to date question on the subject would just like to say have tried all answers from the community but to no avail

1 Answers1

0

You need to have a config file named for your test assembly, like mytests.dll.config. Make sure you copy it to the directory where the test assembly is output.

For excruciating details, see this blog post I wrote a very long time ago: http://charliepoole.org/technical/how-nunit-finds-config-files.html

Charlie
  • 12,928
  • 1
  • 27
  • 31
  • You said app.config in your post and that name won't work. Please consider updating the post if you've made changes. It helps those who are trying to help you and those who read this later as comments tend to be deleted after a while. – Charlie May 06 '21 at 23:06
  • You haven't said what runtime you are targeting. If it's .NET Core, you may want to get away from using `.config` files and switch to a `.runtimeconfig.json` file. – Charlie May 06 '21 at 23:08
  • Thanks Charlie just read this and this is what I figured out. When runtime is .net core I need to use json but when nunit framework it uses app setting.config – Trombone Man May 08 '21 at 21:00