.net框架中的测试 [英] testing in .net framework
问题描述
我已经创建了一个针对.NET Framework 4.6.1的单元测试项目.测试将显示在测试资源管理器"中,并且可以在Visual Studio 2017中正常运行.
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.
我想建立一个构建过程,所以我想从命令行运行测试.我试图使用mstest,但是没有找到测试.
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.
我跑步时
mstest /testcontainer:mp.tests\bin\debug\mp.tests.dll
我知道...
Loading messageparser.tests\bin\debug\messageparser.tests.dll...
Starting execution...
No tests to execute.
但是我可以成功地使用命令'dotnet test'来运行它们.
However I can successfully use the command 'dotnet test' to run them.
我跑步时
dotnet test
我知道...
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
但是我发现的指南建议对.NET Core使用"dotnet测试",而无需提及.NET Framework.
However the guidance I have found suggests that 'dotnet test' should be used for .NET Core with no mention of .NET Framework.
.net Framework项目中,dotnet测试是否是从命令行运行测试的适当方法?还是我应该使用mstest?如果是这样,我如何使它工作?
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?
推荐答案
Mstest.exe
现在已弃用,并且Visual Studio 2017附带了一个名为VSTest.Console.exe
的新工具.您可以在<install root>\Microsoft Visual Studio\2017\<edition>\Common7\IDE\Extensions\TestPlatform
下找到随Visual Studio一起安装的软件.命令行选项在此处记录.
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.
要执行最简单的测试,请运行程序并提供测试项目中输出dll的名称.
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>
这篇关于.net框架中的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!