12

I have created a unit test project targetting .NET Framework 4.6.1. The tests appear in Test Explorer and run fine in Visual Studio 2017.

I want to set up a build process, so I want to run the tests from the command line. I attempted to use mstest but this did not find the tests.

when i run

mstest /testcontainer:mp.tests\bin\debug\mp.tests.dll

I get...

Loading messageparser.tests\bin\debug\messageparser.tests.dll...
Starting execution...
No tests to execute.

However I can successfully use the command 'dotnet test' to run them.

When I run

dotnet test

I get...

Build started, please wait...
Build completed.

Test run for C:\MP.Tests\bin\Debug\MP.Tests.dll(.NETFramework,Version=v4.6.1)
Microsoft (R) Test Execution Command Line Tool Version 15.5.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

Total tests: 70. Passed: 70. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 8.2833 Seconds

However the guidance I have found suggests that 'dotnet test' should be used for .NET Core with no mention of .NET Framework.

Is dotnet test the appropriate way to run tests from the command line for .NET Framework projects? Or should I be using mstest? If so, how do I get it to work?

Dave M
  • 172
  • 3
  • 9
  • "I attempted to use mstest - but this did not work.“ What kind of project are you using? .NET Core console or class library for .NET Framework? `dotnet test` is for .NET Core SDK based projects only (but whether it suddenly works for other project types is uncertain and might not be officially supported). – Lex Li Mar 06 '18 at 18:06
  • @LexLi The test project is targeting .NET Framework, I have updated the question accordingly. – Dave M Mar 07 '18 at 09:27

1 Answers1

1

Mstest.exe is now deprecated and a new tool is included with Visual Studio 2017 called VSTest.Console.exe. You'll find it installed with Visual Studio under <install root>\Microsoft Visual Studio\2017\<edition>\Common7\IDE\Extensions\TestPlatform. Command line options are documented here.

For simplest test execution, run the program and provide the name of the output dll from your test project.

PS E:\ .. \bin\Release>vstest.console.exe MyProject.dll
Microsoft (R) Test Execution Command Line Tool Version 15.7.2
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
Passed   TestMethod1

Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 2.0102 Seconds
PS E:\ .. \bin\Release>
Segfault
  • 8,036
  • 3
  • 35
  • 54