使用 MSBuild 将参数传递给 MSTests

发布于 2024-07-11 19:42:27 字数 269 浏览 5 评论 0原文

我有一个问题想知道是否可以通过特定方式解决。

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

该参数将用作 MSTest 中 TestFixture 设置的条件,以决定使用类的哪个具体实现。 当在构建服务器上运行时,它将是一个模拟版本;当在开发人员计算机上运行时,它将是对物理资产的引用。

这容易实现吗? 我可以设置一个环境变量,但更喜欢 MSTest 和 MSBuild 中是否有可以使用的特定内容。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一笑百媚生 2024-07-18 19:42:27

我发现最简单的方法是编写配置文件。 MsBuild 社区任务使这成为可能。

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

一身骄傲 2024-07-18 19:42:27

作为 xUnit 准则,测试不应接受参数。 它们应该直接运行,无需有人配置它们。

public void TestMethodName()

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

更新:
从您的评论来看,您似乎只需要一个类似于 #define BUILD 的开关。 尝试条件编译符号(项目设置>构建)与 ReplaceCollaboratorsForBuildServer 方法相结合,该方法用 ConditionalAttribute 并在 testFixture 设置方法末尾调用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文