Passing a parameter to MSTests using MSBuild

霸气de小男生 提交于 2019-12-11 15:52:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!