使用MSBuild将参数传递给MSTests [英] Passing a parameter to MSTests using MSBuild

查看:173
本文介绍了使用MSBuild将参数传递给MSTests的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,想知道是否可以通过特定方式解决.

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

我希望能够在将要在TeamBuild服务器上运行的MSBuild脚本中传递参数或设置某种变量.

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.

此参数将用作在MSTest中设置TestFixture的条件,以确定要使用的类的具体实现.在构建服务器上运行时,它将是模拟版本,而在开发人员计算机上运行时,它将是对实物资产的引用.

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.

这很容易做到吗?我可以设置一个环境变量,但希望在MSTest和MSBuild中可以使用某些特定的东西.

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.

推荐答案

作为xUnit准则,测试应采用参数.它们应该运行而无需任何人进行配置.

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

public void TestMethodName()

您的需求似乎更倾向于依赖注入.对于 Spring.Net 这样的框架更合适.

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

更新:
从您的评论看来,您所需要的只是一个类似于#define BUILD的开关.尝试使用条件编译符号(项目设置">构建")以及替换为 ConditionalAttribute ,并在testFixture设置方法的末尾调用.

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.

这篇关于使用MSBuild将参数传递给MSTests的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆