VS 2008 / MSTest - 如何运行所有测试的子集?

发布于 2024-08-12 11:38:49 字数 276 浏览 2 评论 0 原文

我刚刚开始在 Visual Studio 项目中使用 MSTest(我之前使用过 NUnit),我有几个问题。

我发现,如果我右键单击单个测试方法并选择运行测试,它将测试该方法。好的。但是有没有一种方法可以设置一个测试运行,只执行我选择的 x 个测试,而不是所有 y 个测试?我查看了测试菜单及其中的选项,但我不知道如何执行此操作。

另外,如何调试测试的子集?现在,如果我调试我的 MSTest 项目,所有这些项目都会运行。对于初学者的问题,我很抱歉,我一直在研究菜单选项,但对这些问题没有任何了解。谢谢!

I've just started using MSTest in a Visual Studio project (NUnit has been what I've used before) and I have a few questions.

I see that if I right-click on a single test method and choose run tests, it'll test that one method. Good. But is there a way I can set up a test run that only does x of my tests of my choosing, instead of all y of them? I've looked under the test menu and the options in it but I can't figure out how to do this.

Also, how can I debug a subset of my tests? Right now if I debug my MSTest project all of them are run. Sorry for the beginner's questions, I've been kicking around the menu options but nothing has come to me on these issues. Thanks!

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

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

发布评论

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

评论(4

暮光沉寂 2024-08-19 11:38:49

Visual Studio 允许创建测试列表,这正是您想要的。请参阅此处:http://msdn.microsoft.com/en-us/library /ms182462.aspx

此链接也可能有用:http://freekleemhuis.com/2008/04/20/unit-testing-in-visual-studio-2008-part-1/

Visual Studio allows creating test lists, which does exactly what you want. See here: http://msdn.microsoft.com/en-us/library/ms182462.aspx

Also this link may be useful: http://freekleemhuis.com/2008/04/20/unit-testing-in-visual-studio-2008-part-1/

孤云独去闲 2024-08-19 11:38:49

Kona 非常适合您想要保留的列表;我发现很多时候我不需要一个经得起时间考验的列表,只需要一个我可以在接下来的几分钟/小时内运行的列表。

在这种情况下,我使用“测试视图”窗口,突出显示要运行的内容(CTRL + 左键单击 进行多次),然后按运行按钮。

善良,

Kona is right for a list you wish to maintain; I find a lot of the time I don't need a list that stands the test of time, just one I can run for the next few minutes/hours.

In that scenario, I use the Test View window, highlight what you I to run (CTRL + Left Click for multiples) and press the run button.

Kindness,

Dan

噩梦成真你也成魔 2024-08-19 11:38:49

我很惊讶在答案中没有看到的另一个选项是在当前上下文中运行测试。如果您希望运行的测试子集位于相同的测试类或相同的命名空间中,您可以将它们作为一个组运行,而无需对列表或选择进行任何操作。
ctrlr + t 将在光标范围内运行测试。

我发现这确实很有帮助,因为感兴趣的测试(或可能受到更改的影响)往往会本地化到同一个测试类中。测试列表也是另一个需要维护的部分。我注意到添加新测试和重命名旧测试会破坏我所做的列表。因此,如果您有一个完善的小组需要作为一个单元进行测试,那么测试列表可能是最有用的。

例如,如果光标位于测试本身中,则它将仅运行该测试。将几行移到测试之间的空白处,您将运行该类中的所有测试。您还可以将光标移至类外部并运行该命名空间中的所有测试。

namespace Tests
{
    // Cursor here to run all tests in Tests
    [TestClass()]
    public class ClassOfTests
    {
        // Cursor here to run all Tests in this class
        [TestMethod()]
        public void MethodUnderTest_WithThisSetup_ReturnsValue()
        {
            // Cursor here to only run this test
        }

    }

}

Another option which I'm surprised to see not in the answers is the Run Tests in Current Context. If the subset of tests you wish to run is in the same test class or same namespace you can run those as a group without doing anything with the lists or selections.
ctrlr + t will run tests in the scope of the cursor.

This I find really helpful because the tests of interest (Or are likely to be affected by a change) tend to be localized into the same test class. Also the test lists are another piece to maintain. I noticed that adding new tests and renaming old tests break the list I made. And therefore the test lists are probably most useful if you have a well established group you need to test as a unit.

For instance, if the cursor is in the test itself, it will only run that test. Move up a few lines to the space between the tests and you will run all tests in that class. You can also move the cursor to outside of the class and run all tests in that namespace.

namespace Tests
{
    // Cursor here to run all tests in Tests
    [TestClass()]
    public class ClassOfTests
    {
        // Cursor here to run all Tests in this class
        [TestMethod()]
        public void MethodUnderTest_WithThisSetup_ReturnsValue()
        {
            // Cursor here to only run this test
        }

    }

}
只是一片海 2024-08-19 11:38:49

我正在发布关于这个非常老的问题的更新答案。首先,您需要将 [TestCategory("name of my Category gone Here")] 属性添加到要组合在一起的测试方法的顶部。该字符串定义了一个特征。您可以使用 VS2017 中的测试资源管理器按特征对测试进行分组/管理。

还有一些方法可以从命令行运行测试组。 这里是文档

I'm posting an updated answer on this very old question. First you need to add a [TestCategory("name of my category goes here")] attribute to the top of the test methods you want group together. The string defines a trait. You can use the Test Explorer in VS2017 to group/manage tests by trait.

There are also ways to run groups of tests from the commandline. Here is the documentation.

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