问题
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.
回答1:
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.
回答2:
The easiest way to do this that I have found is to write configuration files. There are MsBuild community tasks that make this possible.
来源:https://stackoverflow.com/questions/460775/passing-a-parameter-to-mstests-using-msbuild