Using .config files with NUnit and TestDriven.NET
I just emailed Jamie Cansdale at TestDriven.NET but in the meantime, this might come in useful to someone out there using TestDriven.NET...
As discussed in the FAQ you can use access appSettings values from a .config file.
I discovered a way of making this just a little bit easier to manage:
- Add an
App.Config file to your Class Library root folder along with all your tests, and rename it to match the name of the .dll of the unit test class library (e.g. MyProject.Tests.dll.config)
- Add your config settings (i.e. appSettings and so on) in the normal way
It this point, when
trying to run a test, TestDriven (or possibly NUnit itself?) will not be able to find
your config settings because the config file should really have been
placed in the bin folder but we'd then need to manage 2 copies (one for
each of the Release and Debug folders), and anyway, it's easier for you to see
and manage the config file if it's in the project root folder along with all your other classes rather
than having to move it to the bin folder (because we'd then have to
mess about doing 'show all files' and 'include in project')
To get round this problem without having to move the config file:
- Add a pre-build command to the unit test project:
(i.e. under the Project Properties dialog (Build Events | Pre-Build Command Line)) - enter the following command:
xcopy $(ProjectDir)$(TargetFileName).config /YR
this will copy the [tests.dll].config file to the (Release or Debug) bin folder
Assumptions:
-
This advice applies to VS2003, it is probably very similar for VS2005
but I've not tried it (in fact, if I remember correctly, VS2005 has a
much more intuitive method for copying files into the bin directory at
build time which won't need an xcopy command...)
-
Your unit tests reside in their own Class Library project
UPDATE: Jamie Cansdale has also now
posted on this topic