Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

testing in .net framework

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?

like image 992
Dave Avatar asked Mar 02 '26 05:03

Dave


1 Answers

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>
like image 107
Segfault Avatar answered Mar 03 '26 20:03

Segfault



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!