2
votes

How to pass a parameter to a TeamCity Test Runner?

I've added a build configuration to my teamcity project which copies out a test project from TFS into a local location on the server then it runs the tests with NUnit and display the results.

The problem is that when the tests run from my local pc, they should be using some configurations, when they run from Dev Automated Build and Test Automated Build, they should be using other configurations and all should be in TFS.

For example, BaseUrl and Connection string configurations...

private static readonly string BaseUrl =    ConfigurationManager.AppSettings[AppSettingKey.BaseUrl];

Currently, I've added a web.config file to my project which works fine only locally.

So, how to pass these parameters to a TeamCity Build Configuration which is configured on Dev and Test environemnts?

Even if I create separate web.config files (e.g. dev.web.config and staging.web.config), I need a way to tell the Build Configuration to use which configuration file?

Hope the question is clear.

many thanks.

3

3 Answers

4
votes

Enlightened, found a solution (should have thought more before submiting a question here)!

I'd just create separate dev.app.config and staging.app.config files then on the "Version Control Settings" page on teamcity I can define rules such as copy this file somewhere.

So I just Copy the file onto the root app.config; that's it!

Rule:
+: SolutionName\Tests\ConfigFiles\Dev\App.config=>SolutionName\Tests\App.config
2
votes

Consider using the configuration parameter i.e. Build | Release

Use your debug build locally and release on TeamCity. You can do this with an MSBuild parameter (/p:Configuration=Release)

Then use the solution here (How to select different app.config for several build configurations) to use the correct app.config.

I prefer this solution as it keeps the definitions within the solution / projects rather than within the build.

[I'm adding this just for completeness - I had originally followed this approach but then found the other solution]

1
votes

Rules in Version Control Settings works only for directories so the better approach is to use Build step - command line

Go to Build Step in Settings section and Add Build Step with following settings

Command Line 
Custom script: copy TeamCity.App.config App.config
Execute: Only if all previous steps were successful

Reorder this step and run it before compilation step