在.net框架中测试

Dav*_*ave 5 .net c# automated-tests visual-studio

我创建了一个针对.NET Framework 4.6.1的单元测试项目.测试显示在Test Explorer中,并在Visual Studio 2017中正常运行.

我想建立一个构建过程,所以我想从命令行运行测试.我试图使用mstest,但是没有找到测试.

当我跑

mstest /testcontainer:mp.tests\bin\debug\mp.tests.dll
Run Code Online (Sandbox Code Playgroud)

我明白了......

Loading messageparser.tests\bin\debug\messageparser.tests.dll...
Starting execution...
No tests to execute.
Run Code Online (Sandbox Code Playgroud)

但是我可以成功使用命令'dotnet test'来运行它们.

我跑的时候

dotnet test
Run Code Online (Sandbox Code Playgroud)

我明白了......

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
Run Code Online (Sandbox Code Playgroud)

然而,我发现的指导建议"dotnet test"应该用于.NET Core而不提及.NET Framework.

dotnet测试是否适合从.NET Framework项目的命令行运行测试?或者我应该使用mstest?如果是这样,我该如何让它工作?

Seg*_*ult 1

Mstest.exe现已弃用,Visual Studio 2017 中包含一个名为VSTest.Console.exe. 您会发现它与 Visual Studio 一起安装在<install root>\Microsoft Visual Studio\2017\<edition>\Common7\IDE\Extensions\TestPlatform. 命令行选项记录在此处

对于最简单的测试执行,运行程序并提供测试项目中的输出 dll 的名称。

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>
Run Code Online (Sandbox Code Playgroud)