Runing C# Unit Test with multiple configurations

There is a feature I always use in, in which I create several configurations and each configurations have their own .config file. To my surprise I does not work for my Test Project!  After a little digging and work around I was able to make it work. I am not sure if there is another way of doing it, but this is how it worked for me.

If you are having this issue, I assume that you are very familiar creating .net applications, so let’s dig deep

  1. In the Configuration Manager, create the configurations you need
  2. Copy paste your app.config and add the name of the configuration, in my case is AHI, FIV, MGC, so my config files look like: App.AHI.config, App.MGC.config, App.FIV.Config. You can name it how ever you wanted, but keep the same convention
  3. Add a Post-Build event. In my case it would look like:  xcopy $(ProjectDir)app.$(ConfigurationName).config $(TargetDir)$(TargetName).dll.config /y

it is important that you notice the /y at the end to replace the file

And voila! you know can change the configuration and run your test with different configuration without having to update the config file every time




Leave a Reply

Your email address will not be published. Required fields are marked *