Mar 11 2006
Custom configuration using TestDriven.NET
The TestDriven.NET tool is fantastic. I love the agility it gives you, as you can quickly build your unit tests, write your code and at a right-click, you can run your unit tests from Visual Studio.
One of the problems it currently has (I notice somebody has asked for this in their wishlist) is custom configuration. If the code you’re testing requires settings that would normally be in your web.config or App.config file, you have to ensure these settings are in a file called <your-assembly-name>.dll.config in your bin\Debug directory. A bit inconvenient. NUnit allows you to have a .config file in the root of your project with the same name as your project (e.g., Foo.Bar.config), so why should you do without this feature in Visual Studio?
Well, until the author adds this enhancement (hopefully soon), one workaround I’ve come across for this is to create a Post-Build event in Visual Studio.NET, which copies the config file from the root of your project to the required place in your bin directory.
To set this up, right-click Properties on your Project in Visual Studio.NET. Under Common Properties, click on Build Events. In the Post-build Event Command Line property, add the following: copy $(ProjectDir)$(ProjectName).config $(TargetPath).config
Then, whenever you have a successful build, your latest config changes will be available to TestDriven.NET’s in-built TestRunner.
Related posts

























