我已阅读 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
关于c# - 没有要从 MSTest 执行的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48564785/