I have written a NUnit tests for a .NET application. When I run the NUnit, it does not read the connection string values from the configuration file. I tried many solutions with out success, like
I wasn't able to read the configuration setting even when run in VSNunit. Is there a solution?
I've assumed
SomeNameSpace.MyClassLib
SomeNameSpace.MyClassLib.Test
Try this:
Make sure that you have also copied your app.config
to your NUnit Test DLL class library (i.e. project SomeNameSpace.MyClassLib.Test
) as well.
Build your NUnit Project (e.g. to SomeNameSpace.MyClassLib/bin/debug
) and make sure that following are in the bin\debug (or release) directory
SomeNameSpace.MyClassLib.Test.config
)Edit your NUnit Project in the XML view of the NUnit GUI Project editor (menu Project → Edit, or just edit it in Notepad), and make sure that the test assembly (MyClassLib.Test.dll) and the configuration file names are relative to your appbase
For example,
<NUnitProject>
<Settings activeconfig="Debug" processModel="Default"
domainUsage="Default"
appbase="C:\Temp\MyProject\MyClassLib.Test" />
<Config name="Debug" binpathtype="Auto"
configfile="bin\Debug\MyClassLib.Test.dll.config">
<assembly path="bin\Debug\MyClassLib.Test.dll" />
</Config>
<Config name="Release" binpathtype="Auto" />
</NUnitProject>