MsTest 单元测试可以按类别分组吗
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 /category 选项来过滤 VS 2010 中的测试。
它使用 测试类别属性。有关/category 选项的详细信息。
C# 代码可能如下所示:
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: