Monday, November 19, 2007

NUnit GUI and project config files

I've used NUnit as the unit test framework on a number of projects and all used their own config files to hold connection string settings, etc. On several occasions, I've also used, which is an awesome Visual Studio addin for running unit tests. On my current project, however, I create an NUnit project for my unit test project and store the .nunit file in the same folder as the unit test project's .vbproj file (I'm not using VB by choice ;-) ).

And since I'm using Visual Studio 2005, I don't need to modify the unit test project's Post-Build Event script text to copy/rename the app.config in the output folder because VS does that now.

The problem I ran into was that the config file wasn't getting picked up. I double-checked to make sure the configuration was correct and that the config file was being copied/renamed properly, but it still didn't work. After futzing around with it a bit more, I determined that app.config needs to be copied/renamed the same as the .nunit file name and location.

And to make the arrangement portable across projects, I name the .nunit file the same as the VS project nams. So now my Post-build Event script now looks like this:

:: This script copies and renames app.config to .config
:: so that the NUnit GUI application will consume it.
:: Example:
:: MyTestProject.nunit
:: MyTestProject.config
copy /Y "$(ProjectDir)app.config" "$(ProjectDir)$(ProjectName).config"


No comments: