首页 > 解决方案 > 如何使用 vstest.console.exe 在 cmd 中运行 Specflow 功能/场景?

问题描述

我有一个定义为的功能文件

Feature: Portal Sign in
    In order to login to my portal
    As a User
    I have input user id and password

Scenario: User Login
    Given I have entered username and password 
    When The user clicks on Login button
    Then logged in successfully pop up message should be displayed

我试过这个cmd:

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

但对于给定的测试用例过滤器,它返回没有测试匹配。我错过了什么吗?

另外,您如何建议使用 cmd 运行场景?

编辑:

情况大纲如下

Scenario Outline: Multiple User Login
    Given I have entered <username> and <password>
    When The user clicks on Login button
    Then logged in successfully pop up message should be displayed

Examples:
|username|password|
|User1   |pwd1    |
|User2   |pwd2    |

当我运行下面的 cmd

SpecRun.exe run D:\SpecFlow\bin\Debug\MySpecFlowTests.dll --filter testpath:"Scenario:Multiple+User+Login"

发现的测试显示为 0。

我应该更改任何内容以使其适用于场景大纲吗?

标签: c#.netcommand-line-interfacecommand-promptspecflow

解决方案


当我从命令行在 jenkins 中运行它时,我得到了以下内容。我正在使用 SpecRun 作为跑步者。这确实需要一个 RunSettings 文件。

cd "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow" vstest.console.exe /settings:E\MyPath\To\RunSettings\ E:\MyPathTo\Test.dll /ResultsDirectory:E:\MyPath\ /TestCaseFilter: "(TestCategory=MyTag)"

我创建了一个名为 Jenkins 的文件夹,并且 RunSettings 和 .srprofile 都驻留在该文件夹中。

RunSettings 文件指向 .srprofile

<RunSettings>
  <!-- Configurations for SpecFlow+ Runner -->
  <SpecRun>
   <Profile>Jenkins/MyTest.srprofile</Profile>
   <GenerateSpecRunTrait>false</GenerateSpecRunTrait>
  <GenerateFeatureTrait>false</GenerateFeatureTrait>
  </SpecRun>
</RunSettings>

如果您使用 SpecRun 作为运行程序,您也可以从 cmd 行运行它。相应地更新运行器版本。

cd E:\Path\to\packages\SpecRun.Runner.3.3.*\tools\net461
SpecRun.exe run PathTo/My.srprofile --baseFolder E:\Path\To\bin\Debug --filter "@TagL" --log specrun.log

要按功能名称运行,您将使用:

SpecRun.exe run D:\Path\Jenkins\My.srprofile --baseFolder D:\Path\bin\Debug --filter testpath:"Feature:MyFeature*" --log specrun.log

通配符将匹配以“MyFeature”开头的任何内容。

https://docs.specflow.org/projects/specflow-runner/en/latest/Profile/Filter.html


推荐阅读