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.
You, sir, are an evil genius! I spent ages trying to fix a problem which was caused by this. Thanks :-)
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.
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.
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!!!
Thanks !!!!
You saved my life ^^
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…
Thanks for saving hours of work!
You have saved my life! Many thanks.
What a stupid way for Nunit to work!!!
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.
Try this
copy /Y “$(ProjectDir)App.config” “$(TargetDir)$(TargetFileName).config”
in your Build Events of test project
Just another thank you — my neck was getting sore from banging my head against the wall…
Hurray! 1 hours lost of finding out why my configuration is not loaded!
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…)
Thanks a bunch! Spent days trying to sort this out!
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.
nunit 2.5.9.10348
application base: bin\Debug
configuration file name: .exe.config
replace with your dll or exe name…
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…
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.