Skip to content

NUnit App.Config files – it’s all about the .nunit file!

by Cory Foy on August 24th, 2005

When you are running an assembly test in NUnit, you may need to access App.Config values. NUnit loads the App.config files by looking for a file with AssemblyName.config.

However, in the default configuration, that .config file has to be in the same directory as the .nunit project file. For example, we had the following setup:

\src\MyProject\MyProject.nunit
\src\MyProject\MyProject\MyProject.sln
\src\MyProject\MyProject\bin\debug

putting the MyProject.config file in either \src\MyProject\MyProject or in \src\MyProject\MyProject\bin\debug doesn’t work – NUnit can’t find it. Putting it in \src\MyProject works like a charm.

From → Uncategorized

21 Comments
  1. You, sir, are an evil genius! I spent ages trying to fix a problem which was caused by this. Thanks :-)

  2. I had this same problem and this fixed it. I was using NUnit to test the NHibernate section of my app and it couldn’t find the App.config file. But I didn’t know that.

    What I did was put my NUnit Project inside the bin folder. I also had to change the Properties for Configuration File NAme.

  3. Anonymous permalink

    Wow, that worked! Thanks a ton — I wasted well over an hour trying to figure out why my App.config file was not being found.

  4. Matt permalink

    This helped me. Thanks.

    I found that I had to have my .config file in the same folder as the nunit file. Both had to have the same root name and since I quickly got tired of renaming project.dll.config to project.config, I decided to turn the problem on its head and name the nunit project file project.dll.nunit. It’s been working fine ever since.

    I still don’t like that I have to copy my config file up 2 levels just for nunit to work!!!

  5. Anonymous permalink

    Thanks !!!!

    You saved my life ^^

  6. Rolf Schmidiger permalink

    Please note that the file [myDir]\[myApp].config will only be read if i start “nunit.exe [myDir]\[myApp].nunit”

    (the assembly-name does NOT MATTER.. worked for me like this with Nunit 2.4.)

    Hope this helps somebody…

  7. Anonymous permalink

    Thanks for saving hours of work!

  8. Anonymous permalink

    You have saved my life! Many thanks.

    What a stupid way for Nunit to work!!!

  9. Anonymous permalink

    Here’s another way…..

    If you have an NUnit-enabled project with a .config file, you could just open the assembly (.dll) in NUnit instead of the project (.vbproj or .csproj) or solution (.sln) file. It will find the .config file.

  10. Try this

    copy /Y “$(ProjectDir)App.config” “$(TargetDir)$(TargetFileName).config”

    in your Build Events of test project

  11. Spencer permalink

    Just another thank you — my neck was getting sore from banging my head against the wall…

  12. Anonymous permalink

    Hurray! 1 hours lost of finding out why my configuration is not loaded!

  13. Thanks Rolf Schmidiger et al…

    I had named my nunit file differently than my config:

    Project: ProjectA.csproj
    Test Project: ProjectATester.csproj
    Nunit: ProjectATester.nunit
    Config: ProjectA.config

    Took some time but I finally renamed the nunit file ProjectA.nunit and put the config file in the same directory…

    (This was tougher than it should have been, im thinking…)

  14. Charles Middleton permalink

    Thanks a bunch! Spent days trying to sort this out!

  15. You can specify the File Name in the NUnit GUI under Project–>Edit Configuration File Name. Unfortunately, adding a relative directory doesn’t seem to work. So you have to still place the config file in the same directory as your .nunit project file.

  16. nunit 2.5.9.10348
    application base: bin\Debug
    configuration file name: .exe.config
    replace with your dll or exe name…

  17. sorry – edited above. lame blog doesn’t escape angle-brackets. shame.

    nunit 2.5.9.10348
    application base: bin\Debug
    configuration file name: <assemblyname>.exe.config
    replace <assemblyname>. with your dll or exe name…

  18. Shyam permalink

    Other way ,
    1 . click on file->new project
    2. Change Save as type to dll .
    3. choose nunit test dll as file name .
    4. Ignore warning and click OK
    5.add app.confi to nunit project.
    6. build your project .
    7. run nunit , it will take the config file.

Trackbacks & Pingbacks

  1. How to use NUnit with Visual Studio Express 2008
  2. How to use NUnit with Visual Studio Express 2008
  3. NUnit Testing and Connection Errors | Stuff and Junk

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS