简体   繁体   English

没有从MSTest执行的测试

[英]No tests to execute from MSTest

I have read No tests to execute msTest 我已经读过没有测试来执行msTest

I'm trying to run a unit test (MS unit tests) from the command line. 我正在尝试从命令行运行单元测试(MS单元测试)。 It's my first time attempting this. 这是我第一次尝试这个。

My command works fine (no syntax errors), which is 我的命令工作正常(没有语法错误),这是

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

The problem is I always get the following response in the console 问题是我总是在控制台中得到以下响应

Loading C:\\Users\\me\\source\\repos\\Test03\\UnitTestProject1\\bin\\debug\\UnitTestProject1.dll... 正在加载C:\\ Users \\ me \\ source \\ repos \\ Test03 \\ UnitTestProject1 \\ bin \\ debug \\ UnitTestProject1.dll ...
Starting execution... 开始执行......
No tests to execute. 没有要执行的测试。

My unit test is simply 我的单元测试很简单

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);
        }
     }

Why does it not find the test as I've followed the instructions from https://msdn.microsoft.com/en-us/library/ms182489.aspx#testcontainer ? 为什么它没有找到测试,因为我按照https://msdn.microsoft.com/en-us/library/ms182489.aspx#testcontainer的说明进行操作?

The solution as a whole targets 4.6.1 , I'm using VS 2017 Enterprise 整个解决方案的目标是4.6.1,我正在使用VS 2017 Enterprise

I ran into the same problem and it took me some time to figure out. 我遇到了同样的问题,我花了一些时间才弄明白。 The actual solution is in the comments. 实际的解决方案在评论中。

My Tests are getting discorvered using vstest.console.exe : 我的测试使用vstest.console.exe进行了vstest.console.exe

Visual Studio Enterprise 2017 : Visual Studio Enterprise 2017

"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow\\vstest.console.exe" “C:\\ Program Files(x86)\\ Microsoft Visual Studio \\ 2017 \\ Enterprise \\ Common7 \\ IDE \\ CommonExtensions \\ Microsoft \\ TestWindow \\ vstest.console.exe”

See https://docs.microsoft.com/en-us/visualstudio/test/vstest-console-options for further info. 有关详细信息,请参阅https://docs.microsoft.com/en-us/visualstudio/test/vstest-console-options

If you want to use mstest.exe , you need following reference in your project file: 如果要使用mstest.exe ,则需要在项目文件中使用以下引用:

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

If you have instead (which seems to be the default for newly created test projects): 如果你有(这似乎是新创建的测试项目的默认值):

<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>

you need to use vstest.console.exe 你需要使用vstest.console.exe

Please note that VSTest.Console.exe is optimized for performance and is used in place of MSTest.exe in Visual Studio 2012 . 请注意, VSTest.Console.exe针对性能进行了优化,用于代替Visual Studio 2012中的MSTest.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM