Tilfried Weissenberger

Hi,

our unit-tests in VS actually always target the dev-db. But on TeamBuild to different stages (TEST/STAGING/LIVE) I would like the unit-tests to run against other databases and/or use different configuration from my local one. What's the recommended way of doing this

Is it also possible to have different unit-tests within the same test-run use different configurations




Re: Visual Studio Team System - Testing recommended way of setting configuration in unit-tests

Michael Koltachev - MSFT

Tilfried, here's how you can do that:
1) You can have a .config file per test assembly (/noisolation mstest.exe option does not support that, don't use /noisolation). If you run from command line, and your test assembly is test.dll, just place test.dll.config to the same directory you run test.dll from. Or if you run from IDE, add App.Config file to your test project as project item.
2) For data driven Unit Tests you can have datasource configuration in the .config file, in this way you can change data sources for different test runs without modifying unit test code. Do do that you need to put [DataSource("Tag")] attribute on your [TestMethod] method and define the "Tag" data source in .config file. The following post would tell you how to do that: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=91449&SiteID=1
3) Test Run Configuration is for entire test run. You cannot have different run configs for different tests is the same run but it seems that your scenario doesn't need that, just follow #1 and #2.

Thank you,
Michael Koltachev, VSTS





Re: Visual Studio Team System - Testing recommended way of setting configuration in unit-tests

Martin Kulov - MVP

 Michael Koltachev - MSFT wrote:

Or if you run from IDE, add App.Config file to your test project as project item.

You should bold this one whenever you write it again.

The App.config files should be added to the Test project, otherwise it is just not loaded.

I lost three hours resolving that issue.

You should make it more obvious in some way.

 

Best regards,

Martin Kulov

http://www.codeattest.com/blogs/martin