MsTest 单元测试可以按类别分组吗

发布于 2024-10-04 14:50:06 字数 734 浏览 0 评论 0原文

MbUnit 中,我们可以做这样的事情:

[Test]
[TestCategory("Bad Arguments")]
[TestCategory("Fast")]
[ExpectedException(typeof(ArgumentNullException))]
public void TestCopyWithBadHref()
{
   . . . 
}

注意这两点:

[TestCategory("Bad Arguments")]
[TestCategory("Fast")]

由于 TeamBuild 可以与 MsTest 集成来执行门控签入和/或在夜间运行,所以这是一项很棒的功能!但是,考虑到某些测试可以运行很长时间,因此可以方便地将它们分为应在每次签入确认之前运行的测试和应在夜间运行的测试(由于其持续时间以及其他原因)。因素。

实现这一目标的一种方法可能是创建多个项目 - 一个用于慢速测试,一个用于快速测试,等等。但是,这种分离很不方便。项目依赖性感觉不太自然,而且某些测试可能属于多个逻辑类别。

如果 MsTest 具有类似于 MbUnit 长期以来的功能,那就太好了。例如,可以运行 MbUnit.Cons.exe 并指定要与命令行开关一起使用的类别。

如何使用 MsTest 实现相同的效果?我们是一家 MSFT 商店,我未能将 MbUnit 出售给我的同事。

In MbUnit one can do something like this:

[Test]
[TestCategory("Bad Arguments")]
[TestCategory("Fast")]
[ExpectedException(typeof(ArgumentNullException))]
public void TestCopyWithBadHref()
{
   . . . 
}

Note these two:

[TestCategory("Bad Arguments")]
[TestCategory("Fast")]

Since TeamBuild can be integrated with MsTest to perform gated check-ins and/or run at night, it is a great feature! However, given that some tests can run for a long time, it is convenient to separate them into the tests that should run before every check-in is confirmed, and the tests that should run at night instead due to their duration as well as other factors.

One way to go about achieving this might be creating several projects - one for slow tests, one for fast tests, etc. However, this separation is inconvenient. Project dependencies would not feel as natural, plus some tests can be in more than one logical category.

It would be great if MsTest had something similar to what MbUnit has had for a long time. For instance, one can run MbUnit.Cons.exe and specify the category to be used with a command-line switch.

How can I achieve the same using MsTest? We are a MSFT shop, and I failed to sell MbUnit to my co-workers.

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

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

发布评论

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

评论(1

你列表最软的妹 2024-10-11 14:50:06

您可以使用 /category 选项来过滤 VS 2010 中的测试。

它使用 测试类别属性。有关/category 选项的详细信息。

C# 代码可能如下所示:

[Description("test 123456"), TestCategory("Edit Tests"), TestCategory("Non-Smoke"), TestMethod]
public void VerifyEditsPersist()

You can use the /category option to filter the tests in VS 2010.

It uses the testcategory attribute. Details on the /category option.

C# code might look something like this:

[Description("test 123456"), TestCategory("Edit Tests"), TestCategory("Non-Smoke"), TestMethod]
public void VerifyEditsPersist()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文