Skip to content

Cory Foy

Organizational agility through intersecting business and technology

Menu
  • FASTER Fridays
  • Mapping Mondays
  • Player Embed
  • Search Videos
  • User Dashboard
  • User Videos
  • Video Category
  • Video Form
  • Video Tag
Menu

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

Posted on August 24, 2005 by Cory Foy

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.

21 thoughts on “NUnit App.Config files – it’s all about the .nunit file!”

  1. Jack says:
    April 5, 2006 at 10:35 am

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

  2. Praveen Angyan says:
    May 28, 2006 at 3:27 am

    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:
    July 7, 2006 at 3:14 pm

    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:
    September 8, 2006 at 8:19 pm

    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:
    December 12, 2006 at 10:20 am

    Thanks !!!!

    You saved my life ^^

  6. Rolf Schmidiger says:
    May 10, 2007 at 3:27 am

    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:
    May 15, 2007 at 5:02 am

    Thanks for saving hours of work!

  8. Anonymous says:
    May 13, 2008 at 5:58 am

    You have saved my life! Many thanks.

    What a stupid way for Nunit to work!!!

  9. Anonymous says:
    June 25, 2008 at 11:20 am

    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:
    July 14, 2008 at 5:13 pm

    Try this

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

    in your Build Events of test project

  11. Spencer says:
    August 28, 2008 at 10:35 am

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

  12. Anonymous says:
    June 14, 2009 at 10:23 am

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

  13. Pingback: How to use NUnit with Visual Studio Express 2008
  14. Pingback: How to use NUnit with Visual Studio Express 2008
  15. LKlein says:
    December 8, 2009 at 7:00 pm

    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:
    December 22, 2009 at 6:39 am

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

  17. Markus Gallagher says:
    March 4, 2010 at 6:46 am

    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.

  18. jeremy simmons says:
    April 5, 2011 at 12:37 pm

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

  19. jeremy simmons says:
    April 5, 2011 at 12:38 pm

    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…

  20. Pingback: NUnit Testing and Connection Errors | Stuff and Junk
  21. Shyam says:
    May 3, 2012 at 2:38 pm

    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.

Comments are closed.

© 2025 Cory Foy | Powered by Superbs Personal Blog theme