简体   繁体   中英

No tests to execute from MSTest

I have read No tests to execute msTest

I'm trying to run a unit test (MS unit tests) from the command line. 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

The problem is I always get the following response in the console

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

The solution as a whole targets 4.6.1 , I'm using 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 :

Visual Studio Enterprise 2017 :

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

If you want to use mstest.exe , you need following reference in your project file:

<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

Please note that VSTest.Console.exe is optimized for performance and is used in place of MSTest.exe in Visual Studio 2012 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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