首页 文章

使用mstest.exe和VS2017按类/类别过滤

提问于
浏览
2

Edit: 这是一个Visual Studio 2017问题 . 用VS2015重复相同的程序,所有工作都是如此 .

我在VS2017中创建了一个简单的单元测试项目,并进行了两次单元测试 . 这些测试标有“Ores”类别,如下所示:

[TestClass]
public class Copper
{
    [TestCategory("Ores"), TestMethod]
    public void CheckCopper()
    {
        DataMiner locMiner = new DataMiner();

        string result = locMiner.GetCopper();

        Assert.AreEqual("Copper", result);
    }
}

现在我尝试通过带有/ category过滤器的命令行使用mstest.exe运行此测试 . 完整的调用是:mstest /testcontainer:TestSystem.dll / category:Ores

MSTest.exe通过Path变量链接:“C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Enterprise \ Common7 \ IDE;”

I get the "No test to execute" message. 如果我将类别写为"Ores"或Ores,则无关紧要 . 如果没有/ category过滤器,则会按预期运行mit测试 .

使用类别的testrun失败 .
enter image description here
没有类别没有问题 .
enter image description here

1 回答

  • 1

    在MS工作人员的友好帮助下,我找到了解决方案 .

    首先澄清一下: mstest.exe is not intended to support VS2017 created MSTestV2 assemblys. 也许我没有深入挖掘或者记录不好......

    无论如何, vstest.console.exe is the proper way to execute command line based unit testing with this configuration.

    但是存在一个不同的缺陷:VS2017安装了两个版本的vstest.console.exe .

    The outdated, not working one: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe",版本号15.0.0.0

    The version to use: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe",版本号15.0.26720.2

    最后,VS2017 MSTestV2的工作执行示例创建了具有过滤器激活的测试组件:vstest.console.exe works fine

相关问题