如何通过cmd运行多个Specflow项目? [英] How to run multiple specflow projects through cmd?

查看:82
本文介绍了如何通过cmd运行多个Specflow项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多.Net Framework类库项目,都安装了specflow和specrun.specflow nuget软件包.

I have numerous .Net Framework class library projects, all with specflow and specrun.specflow nuget packages installed.

我能够在Visual Studio 2019的测试资源管理器中运行所有这些项目,但我想知道是否可以使用cmd提示符运行它.

I'm able to run all these projects in the Test explorer of Visual Studio 2019 but I want to know if this can be run using cmd prompt.

我计划通过创建一个批处理文件以通过cmd运行所有项目而无需在VS 2019中运行测试资源管理器并手动运行它们来实现自动化

I'm planning to automate by creating a batch file to run all the projects through cmd without having to go test explorer in VS 2019 and run them manually

有人可以实现吗?如果可能的话,能否请您分享运行它们所需的命令?

Does anybody have any idea if this can be achieved? If possible, can you please share the commands needed to run them?

根据格雷格·伯格哈特(Greg Burghardt)的建议,我做了以下事情

Based on Greg Burghardt's suggestion, I did the following

  1. 我转到了vstest.console.exe所在的路径(C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ Common7 \ IDE \ Extensions \ TestPlatform)
  2. 从该路径打开cmd并运行cmd vstest.console.exe mytests.dll 刚开始我遇到一个错误,说找不到上面的dll,所以我将dll粘贴到了相同的位置,并再次执行相同的命令,我得到了以下消息
  1. I went to the path where vstest.console.exe is present(C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform)
  2. Opened cmd from that path and ran the cmd vstest.console.exe mytests.dll At first I got an error saying that the above dll was not found, so I pasted the dll to the same location and upon executing the same command again, I got the below message

C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ Common7 \ IDE \ Extensions \ TestPlatform \ mytests.dll中没有可用的测试.确保测试发现者&遗嘱执行人已注册,平台和框架版本设置合适,然后重试.

No test is available in C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform\mytests.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

此外,可以使用/TestAdapterPath命令指定测试适配器的路径.示例/TestAdapterPath:.

Additionally, path to test adapters can be specified using /TestAdapterPath command. Example /TestAdapterPath:.

我没有提供复制dll并将其粘贴到vstest.console.exe路径位置的方法,而是直接提供了dll所在的路径,并运行了dll内部存在的所有测试因此,cmd看起来会像

Instead of copying the dll and pasting it to the vstest.console.exe path location, I directly provided the path where the dll is residing and that ran all the tests that were present inside the dll so the cmd, will look something like

vstest.console.exe D:\ Specflow \ Dummy \ bin \ Debug \ mytests.dll

推荐答案

使用Visual Studio附带的 vstest.console.exe 命令行实用程序.该可执行文件被埋在Visual Studio安装目录的深处.您可以通过在Windows文件资源管理器中搜索"vstest.console.exe"来找到计算机上的确切路径.在Visual Studio的安装文件夹中.

Use the vstest.console.exe command line utility that comes with Visual Studio. This executable is buried deep inside the Visual Studio installation directory. You can find the exact path on your machine by searching Windows File Explorer for "vstest.console.exe" inside the installation folder for Visual Studio.

基本的命令行参数是:

path\to\vstest.console.exe path\to\tests.dll

这将在构建测试项目所生成的DLL文件中运行所有测试.有无数的过滤选项.

That runs all tests in the DLL file generated by building a test project. There are a myriad of filtering options.

使用SpecFlow标记从命令行运行测试很容易.每个标签都变成一个 [TestCategory] ​​属性,因此只需使用TestCategory过滤器即可:

Running tests from the command line by SpecFlow tag is easy. Each tag becomes a [TestCategory] attribute, so just use the TestCategory filter:

path\to\vstest.console.exe path\to\tests.dll /TestCaseFilter:"TestCategory=SpecFlowTagName"

作为一个例子,假设您有这种情况:

As an example, let's say you have this scenario:

Feature: Application Security
    In order to ...
    As a ...
    I want to ...

@SmokeTest
Scenario: Logging in
    Given "tester" is a registered user
    When the user logs in as "tester"
    Then the user should see their dashboard

上面的方案有一个与之关联的标签:SmokeTest.您可以运行此方案,也可以运行带有"SmokeTest"标签的任何其他方案.使用此命令:

The scenario above has one tag associated with it: SmokeTest. You can run this scenario, and any other scenario tagged with "SmokeTest" using this command:

path\to\vstest.console.exe path\to\tests.dll /TestCaseFilter:"TestCategory=SmokeTest"

按功能运行SpecFlow测试

每个功能都上了一个测试类.功能标题(不是文件名.在功能文件的功能:..." 内部之后的文本)被上载为C#类名.非字母数字字符将转换为"_".人物.然后,单词特征"被替换为特征".附加到它.

Run SpecFlow Tests By Feature

Each feature is turned in to a test class. The feature title (not the file name. The text that comes after "Feature: ..." inside the feature file.) is turned in to a C# class name. Non alpha numeric characters are converted to "_" characters. Then the word "Feature" is appended to it.

使用此示例功能:

Feature: Application Security
    In order to ...
    As a ...
    I want to ...

功能标题为 Application Security ,因此测试类名为 ApplicationSecurityFeature .现在,您可以使用全名运行整个功能文件:

The feature title is Application Security, so the test class is named ApplicationSecurityFeature. Now you can run that whole feature file by full name:

vstest.console.exe tests.dll /TestCaseFilter:"FullyQualifiedName~ApplicationSecurityFeature"

按方案运行SpecFlow测试

这只是按功能运行它们的一种变体.功能文件中的每个方案都将成为一种测试方法.方案的标题将转换为C#类名,并用"_"替换所有非字母数字字符.

Run SpecFlow Tests By Scenario

This is just a variation of running them by feature. Each scenario in a feature file becomes a test method. The title of the scenario is converted to a C# class name, replacing all non alpha numeric characters with "_".

提供此功能和方案:

Feature: Application Security
    In order to ...
    As a ...
    I want to ...

Scenario: Logging in
    ...

类名是"ApplicationSecurityFeature";并且测试方法名称为 LoggingIn .再次,使用完全限定的名称运行:

The class name is "ApplicationSecurityFeature" and the test method name is LoggingIn. Again, run by fully qualified name:

vstest.console.exe tests.dll /TestCaseFilter:"FullyQualifiedName~ApplicationSecurityFeature.LoggingIn"


可以在Microsoft.com上找到有关vstest命令行选项的更多信息: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆