c# - 没有要从 MSTest 执行的测试

标签 c# visual-studio unit-testing

我已阅读 No tests to execute msTest

我正在尝试从命令行运行单元测试(MS 单元测试)。这是我第一次尝试这个。

我的命令工作正常(没有语法错误),这是

mstest /testcontainer:C:\Users\me\source\repos\Test03\UnitTestProject1\bin\debug\UnitTestProject1.dll

问题是我总是在控制台中得到以下响应

Loading C:\Users\me\source\repos\Test03\UnitTestProject1\bin\debug\UnitTestProject1.dll...
Starting execution...
No tests to execute.

我的单元测试很简单

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void AddPositive()
        {
            var bll = new ConsoleApp1.Bll();
            var result = bll.Add(2, 5);
            Assert.IsTrue(result == 7);
        }
     }

为什么我按照 https://msdn.microsoft.com/en-us/library/ms182489.aspx#testcontainer 中的说明找不到测试?

整个解决方案针对 4.6.1 ,我使用的是 VS 2017 Enterprise

最佳答案

如果你想使用mstest.exe,你需要在你的项目文件中引用以下内容:

<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />

如果你有(这似乎是新创建的测试项目的默认设置):

<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>

你需要使用vstest.console.exe

请注意VSTest.Console.exe is optimized for performance and is used in place of MSTest.exe in Visual Studio 2012 .

关于c# - 没有要从 MSTest 执行的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48564785/

相关文章:

c# - 使用 C# 进行 JSON 反序列化的问题

c# - 为什么我的 Enum 参数恢复为默认值?

c++ - unicode utf-16代理对打印问题

python - 如何在 pytest 中将单元测试和集成测试分开

c# - 进度条不工作

c# - 在java和c#中使用hmac/sha512生成哈希值

c# - 在 MVC 中隐藏/显示属性和排序属性

c - 从此函数传递值

javascript - 如何在我的案例中测试 http 请求

python - 如何单元测试命令行参数?