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

17 Responses to “NUnit App.Config files – it’s all about the .nunit file!”

  1. Jack says:

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

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

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

    Thanks !!!!

    You saved my life ^^

  6. Rolf Schmidiger says:

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

    Thanks for saving hours of work!

  8. Anonymous says:

    You have saved my life! Many thanks.

    What a stupid way for Nunit to work!!!

  9. Anonymous says:

    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. Urmil Shah says:

    Try this

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

    in your Build Events of test project

  11. Spencer says:

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

  12. Anonymous says:

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

  13. [...] named correct (TestProject.dll.config). Unfortunately this was not the case…. Then I found a blog entry from Cory Foy, explaining that my .config was at the wrong directory. I had the same project structure as Cory, [...]

  14. [...] I had the same project structure as Cory, so I had to place the config in another place. Another useful tip found in the comments of Corys blog: Just open the TestProject.dll using NUnit, and all references are set correct [...]

  15. LKlein says:

    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…)

  16. Charles Middleton says:

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

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

Leave a Reply