我可以根据项目自动将测试分配到测试列表吗?

发布于 2024-11-30 00:35:38 字数 482 浏览 3 评论 0原文

我最近将我们模糊定义的单元测试项目分为两个项目,一个用于单元测试,另一个用于(我们的大部分测试)集成测试。这是希望不那么巧妙地促使我们的开发团队(包括我自己)编写更好的测试和更容易测试的代码。 (并且,通过扩展,更容易单元测试。)

在这样做时,我发现在 Visual Studio 中使用 MSTest 实际上有点令人沮丧,因为它很慢,但更重要的是它想要运行给定解决方案中的所有测试,而不是给定项目中的所有测试。我已经跨越了第一个障碍,因为我最终遇到了测试列表编辑器,它允许您创建列表,然后将测试分配到列表。我创建了一个单元测试列表,检查了单元测试项目中的所有测试并将它们拖过来,并对集成测试执行了相同的操作。您可以独立于任何其他列表运行每个列表。

这让我们触及了问题的核心:是否有可能简单地让这些列表自行增长?即,我可以将整个项目绑定到一个列表,或者至少让列表自行更新吗?我想让我们的开发人员(包括我自己)尽可能轻松地使这些列表保持最新,最重要的是,实际运行测试。

I've recently split our nebulously-defined unit testing project into two projects, one for unit testing and one for (what the bulk of our tests are) integration tests. This is with the hope of not-so-subtly prodding our dev team (myself included) to write better tests and code that is more easily tested. (And, by extension, more easily unit tested.)

In doing so, I've found using MSTest within Visual Studio to actually be kind of frustrating, as it is slow but more importantly it wants to run all tests in a given solution rather than all tests in a given project. I've crossed this first hurdle, as I eventually came across the Test List Editor, which allows you to create lists and then assign your tests to the list. I created a list for unit tests, checked all of the tests from the unit test project and dragged them over, and did the same for the integration tests. You can run each list independently of any others.

This gets us to the heart of the matter: Is it possible to simply have these lists grow on their own? IE., can I tie an entire project to a list, or at the very least have the lists update themselves? I want to make it as easy as possible on our developers (myself included) to keep these lists up to date and, most importantly, to actually run the tests.

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

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

发布评论

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

评论(2

愿得七秒忆 2024-12-07 00:35:38

在测试视图(测试 -> Windows -> 测试视图)和测试结果(测试 -> Windows -> 测试结果)中,您可以按许多不同的标准对测试进行分组,其中之一是项目。然后,您可以在测试视图中选择一个项目并单击“运行选择”按钮。


编辑:

请注意,如果您希望新测试在测试视图中自动更新,则需要在“工具 -> ”中取消选中“禁用测试方法的后台发现”选项; 选项 -> 测试工具 -> 测试项目”(进行此更改后重新启动 VS)。如果选中此选项,则需要在添加任何新测试之前单击刷新。


编辑2

更多信息:您可以为“运行选择”分配键盘快捷键(例如Ctrl R,S),这样您就可以运行当前在测试视图中选择的项目的所有测试,甚至如果测试视图窗口没有焦点(但需要在某处打开)。因此,在测试视图中,您可以选择当前正在使用的项目,在该项目中打开一个测试类,添加一个测试,然后立即按下键盘快捷键,项目中的所有测试(包括新测试)都将运行。

In Test View (Test->Windows -> Test View) and Test Results (Test -> Windows -> Test Results) you can group the tests by a number of different criteria, one of which is Project. In Test View you can then select a project and click on the 'run selection' button.


Edit:

Note that if you want new tests to automatically update in the test view, you need to uncheck the "disable background discovery of test methods" option in "Tools -> Options -> Test Tools -> Test Project" (restart VS after making this change). If this option is checked, you need to click refresh before any new tests are added.


Edit 2

Some more info: You can assign a keyboard shortcut to "Run selection", (e.g. Ctrl R, S) so you can run all tests for the project that is currently selected in the test view even if the test view window doesn't have focus (It needs to be open somewhere though). So in Test View you can select the project you are currently working in, Open up a test class in that project, add a test, and immediately press your keyboard shortcut, and all tests in the project, including the new one, will be run.

GRAY°灰色天空 2024-12-07 00:35:38

我认为您正在寻找测试类别

I think you are looking for test categories.

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