|
This post originated from an RSS feed registered with .NET Buzz
by Darrell Norton.
|
Original Post: Keeping NUnit config files in sync
Feed Title: Darrell Norton's Blog
Feed URL: /error.htm?aspxerrorpath=/blogs/darrell.norton/Rss.aspx
Feed Description: Agile Software Development: Scrum, XP, et al with .NET
|
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Darrell Norton
Latest Posts From Darrell Norton's Blog
|
|
When doing Test-Driven Development with NUnit, you can add an application config file by adding a file called AssemblyName.dll.config to the executing directory. In VB it's not a problem since the bin directory is it (you could just add the config file to the bin directory and "include in project"), but in C# there is a Debug and a Release subdirectory under bin depending on the Visual Studio solution configuration.
The problem is getting your NUnit config file into those directories without having to maintain two copies. The answer is Build Events, specifically post-build events.
First, add an App.config file to your unit test project. Copy everything from your current AssemblyName.dll.config file into the App.config file. The problem is if your project is a class library, Visual Studio won't rename the file and copy it to the output directory like it does with a Windows Forms project.
Now right-click on the unit test project, select Properties, and select Build Events. Click the ellipses (...) next to Post-build Event Command Line. This will open up a batch file editor. Click the Macros >> button to see which macros are available to you. It even shows you the values you can expect given your current project configuration.
That was just handy information for your benefit. Here is the post-build event you would use to copy your App.config to the output directory and rename it to AssemblyName.dll.config (copy and paste):
copy /Y "$(ProjectDir)App.config" "$(TargetDir)$(TargetFileName).config"
Now when you rebuild your project, the App.config file will be renamed to AssemblyName.dll.config and copied to the output directory so that NUnit can access it for configuration information. Note that this should work for VB too, in case you want to keep source-controlled files out of your bin directory. Simple!
Read: Keeping NUnit config files in sync