views:

1127

answers:

2

I've got an issue that was wondering if could be solved in a particular way.

I would like to be able to pass a parameter or set some kind of variable in an MSBuild script that will be run on a TeamBuild server.

This parameter would be used as a condition in the setup of a TestFixture in MSTest to decided which concrete implementation of a class to be used. It would be a mock version when running on the build server, and a reference to a physical asset when running on a developer machine.

Is this easily possible? I could set an environment variable but would prefer if there was something specific in MSTest and MSBuild that could be used.

A: 

As a xUnit guideline, tests should not take in parameters. They should just run without someone having to configure them.

public void TestMethodName()

Your need seems to be more towards dependency injection. For which frameworks like Spring.Net are a better fit.

Update:
From your comment, it seems all you require is a switch similar to a #define BUILD. Try Conditional Compilation symbols (Project Settings>Build) coupled with a ReplaceCollaboratorsForBuildServer method that is decorated with the ConditionalAttribute and called at the end of your testFixture Setup method.

Gishu
We're using Unity, but we're wanting to avoid having to use elaborate configuration files to set up the tests, hence why one piece of information stating that it was running on a build server which could be accessed from code would be sufficient.
Campbell
A: 

The easiest way to do this that I have found is to write configuration files. There are MsBuild community tasks that make this possible.

Precipitous