在.net框架中测试

2023-12-23

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

我想设置一个构建过程,所以我想从命令行运行测试。我尝试使用 mstest 但这没有找到测试。

当我跑步时

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.

但是我可以成功使用命令“dotnet test”来运行它们。

当我跑步时

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

然而,我发现的指南表明“dotnet test”应该用于 .NET Core,而不提及 .NET Framework。

dotnet test 是从命令行运行 .NET Framework 项目测试的适当方法吗?或者我应该使用 mstest ?如果是这样,我该如何让它发挥作用?


Mstest.exe现已弃用,Visual Studio 2017 中包含一个新工具,名为VSTest.Console.exe。您会发现它与 Visual Studio 一起安装在<install root>\Microsoft Visual Studio\2017\<edition>\Common7\IDE\Extensions\TestPlatform。命令行选项有记录在这里 https://learn.microsoft.com/en-us/visualstudio/test/vstest-console-options?view=vs-2017.

对于最简单的测试执行,运行程序并提供测试项目中的输出 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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在.net框架中测试 的相关文章

随机推荐