使用 MSTest 仅运行所有测试集的一部分
我想知道是否有任何简单方法可以使用 MSTests 运行特定类别的测试。我目前有一些单元和集成测试。一般来说,我只想运行单元测试。
我知道您可以用类别标记每个测试方法,但从我所看到的来看,它似乎只有在您想创建不同的测试列表时才有用。这似乎不太有用,因为对于每个新测试,我都必须更新该列表。
我还尝试过将集成测试放在一个项目中,将单元测试放在另一个项目中,但我只能看到运行测试的 3 个选项:解决方案、上下文范围测试和受影响测试,所以我想这没有多大帮助。
你们是怎么做到的?
谢谢
I'd like to know if there is any simple way of running with MSTests a certain category of tests. I currently have some Unit and Integration tests. Generally, I just want to run Unit-Tests.
I know you can tag each test method with a category, but from what I've seen it seems like it is only useful if you want to create different tests lists. That doesn't seem so useful, as for each new test I'd have to update that list.
I've also tried putting Integration tests in one project and Unit tests in another one, but I can see only 3 options for running tests: Solution and Context-Wide and Impacted tests, so I guess this doesn't help a lot.
How do you guys do it?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您尝试在什么背景下运行测试?在 CI 期间?在你的开发盒上构建之后?我个人认为使用类别是最好的方法。您不必创建列表。在测试列表编辑器中,您可以按类别排序。只需突出显示具有“UnitTest”类别(或其他类别)的所有测试,检查所有并运行选定的。
此外,如果它们位于不同的项目中,那么您可以按项目分组并选择单元测试项目中的所有项目。
Under what context are you trying to run the tests? During CI? After building on your dev box? Personally I believe using the categories is the best way to go. You don't have to create a list. On the Test List Editor you can sort by category. Just highlight all of the tests with "UnitTest" category (or whatever) check all and run selected.
Additionally, if you have them in different projects then you can group by project and select all those in the unit test project.
对于在最初提出这个问题两年半后现在运行 VS2012 的任何人,您可以单击“测试”->“Windows”->“测试资源管理器”,然后单击搜索框和组左侧的小树/层次结构图标您的测试,并选择按“特征”进行分组 - 显然“特征”意味着“测试类别”。然后您可以右键单击分组来运行/调试您的测试。
或者,如果您愿意,您可以下降到命令行并按类别运行测试,尽管我更喜欢使用 GUI 测试运行器运行测试,这样我就不必下降到命令行,这样我就可以单击测试可直接进入相关测试代码。执行此操作的说明如下:http://msdn.microsoft.com/en -us/library/dd286683.aspx
For anyone running VS2012 now two and a half years after this question was originally asked, you can click on Test->Windows->Test Explorer and then click on the little tree/hierarchy icon to the left of the search box and group your tests, and choose to group by "Traits" - apparently "traits" means "TestCategories." Then you can right click on the groupings to run/debug your tests.
Or if you prefer, you can drop to the command line and run tests by category, though I'd prefer running tests with a GUI test runner, so that I don't have to drop to the command line, and so that I can click on tests to be taken directly to the test code in question. The instructions for doing so are here: http://msdn.microsoft.com/en-us/library/dd286683.aspx
如果您运行(“调试”)整个测试项目,它将运行该项目中的所有测试。如果您对测试有严格的分区,这非常有用。
否则,您必须使用测试列表(在“测试”菜单中),这对我来说似乎不太有效。它们有时似乎会被自动覆盖。
If you run ("Debug") a whole test project, it will run all the tests in the project. This is useful if you have strict partitions of your tests.
Otherwise, you have to use Test Lists (in the Test menu), which never seems to work well for me. They seem to get overwritten automatically sometimes.