testing in .net framework

微笑、不失礼 提交于 2020-02-24 00:37:19

问题


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?


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


来源:https://stackoverflow.com/questions/49136887/testing-in-net-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!