如何使用vstest.console.exe在cmd中运行Specflow功能/方案? [英] How to run Specflow feature/scenarios in cmd using vstest.console.exe?
问题描述
我有一个类似的特征文件
I have a feature file defined like
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"
,但对于给定的测试用例过滤器,它不返回任何测试匹配项.我想念什么吗?
but it returns with no test matches for the given test case filter. Am I missing anything?
您还建议如何使用cmd运行方案?
Also how do you suggest to run scenarios using cmd?
如遇以下情况,请概述大纲
In case of scenario Outline like the one below
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
When I run the below cmd
SpecRun.exe run D:\SpecFlow\bin\Debug\MySpecFlowTests.dll --filter testpath:"Scenario:Multiple+User+Login"
发现的测试显示为0.
我应该进行任何更改以使其适用于方案大纲吗?
Should I change anything to make it work for scenario outline?
推荐答案
当我从命令行在jenkins中运行此程序时,我看到了以下内容.我正在为跑步者使用SpecRun.这确实需要一个RunSettings文件.
When I ran this in jenkins from a command line I had the below. I am using SpecRun for a runner. This did require a RunSettings file.
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都驻留在该文件夹中.
I created a folder called Jenkins and the RunSettings and .srprofile both resided in that folder.
RunSettings文件指向.srprofile
RunSettings file pointed to the .srprofile
<RunSettings>
<!-- Configurations for SpecFlow+ Runner -->
<SpecRun>
<Profile>Jenkins/MyTest.srprofile</Profile>
<GenerateSpecRunTrait>false</GenerateSpecRunTrait>
<GenerateFeatureTrait>false</GenerateFeatureTrait>
</SpecRun>
</RunSettings>
如果将SpecRun用作运行程序,则也可以从cmd行运行它.相应地更新亚军版本.
If you are using SpecRun as a runner, you can also run this from a cmd line. Update the runner version accordingly.
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
要通过功能名称运行,您将使用:
To run by a Feature Name, you would use:
SpecRun.exe run D:\Path\Jenkins\My.srprofile --baseFolder D:\Path\bin\Debug --filter testpath:"Feature:MyFeature*" --log specrun.log
通配符将匹配以"MyFeature"开头的所有内容.
wild card will match anything starting with "MyFeature".
https://docs.specflow.org/projects/specflow-runner/zh-CN/latest/Profile/Filter.html
这篇关于如何使用vstest.console.exe在cmd中运行Specflow功能/方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!