我一直在使用SpecFlow进行验收测试.这使用Gherkin(DSL Cucumber使用).它包含一个名为"标签"的有趣功能.我可以看到它的实用性,但我不确定在BDD中使用标签可能构成什么样的好习惯.
我用谷歌搜索了一下,但不幸的是,包括"Tag"这个词与许多非Gherkin标签相匹配(就像这个页面上的那些!)
我希望在Cucumber维基上找到一些帮助,但标签主题尚未编写.
我发现声明"您可以使用标签将功能和方案分组,与您的文件和目录结构无关",但我恐怕不知道这意味着什么!
这是我们的一项验收测试的示例:
Feature: Add an effect to a level
In order to create a configuration
As a user
I want to be able to add effects to a level
Scenario: Add a new valve effect to a level
Given I have created a level named LEVEL123 with description fooDescription
And I am on the configuration page
When I click LEVEL123 in the level tree
And I expand the panel named Editor Panel
And I click the Add Valve Effect button
And …Run Code Online (Sandbox Code Playgroud) 简而言之,我需要的是创建一个Scenario Outline,其中包含一个可重复的步骤,而不必使用多个AND键入它,如下所示:
Scenario Outline: outline
Given I am a user
When I enter <x> as an amount
And I enter <x2> as an amount
Then the result should be <result>
Scenarios:
|x|x2|result|
|1|2 |3 |
|1|0 |1 |
Run Code Online (Sandbox Code Playgroud)
但是,我想做类似以下的事情:
Scenario Outline: outline
Given I am a user
When I enter <Repeat: x> as an amount
Then the result should be <result>
Scenarios:
|x |result|
|1,2,3|6 |
|1,2 |3 |
Run Code Online (Sandbox Code Playgroud)
基本上,我希望"我输入金额"分别运行3次和2次.
我发现这个问题的最接近的是如何重新运行具有不同参数的黄瓜场景轮廓?,但我想在放弃并使用带有逗号分隔列表或类似内容的StepArgumentTransformation之前仔细检查.
我最后的答案更像是这样的:
Scenario Outline: outline
Given I am …Run Code Online (Sandbox Code Playgroud) 有没有人知道实现这一目标的方法,或者他们认为这是一个好主意.在Gherkin中使用OR样式语法来减少重复但保持人类可读性(希望如此).我正在考虑使用多个OR语句的每个组合扩展子句组合的情况.例如
Scenario: TestCopy
Given Some text is selected
When The user presses Ctrl + C
OR the user right clicks and selects copy
OR the user selects Edit + Copy
Then the text is copied to the clipboard
Run Code Online (Sandbox Code Playgroud)
这将作为3个测试运行,每个测试使用相同的给定,然后使用一个来自OR集合.我想这可以使用带有When子句的占位符的模板来实现,但我认为这更具可读性,并且可以允许OR在Given中使用以产生nxm测试.使用大纲,您仍然需要nxm行.
谢谢.
是否有类似目标的一个项目作为Specflow是黄瓜在Visual Studio中,但对于cucumberjs?
我正在考虑Visual Studio的单元测试/ bdd框架.Cucumberjs似乎是一个明显的选择,因为我正在使用Specflow来测试c#.但是,cucumberjs需要安装nodejs.
Chutzpah在Visual Studio中运行像jasmine,qunit等.有没有办法为cucumberjs做同样的事情?也许是visualstudio的nodejstools与其他东西的混合?
有一个功能请求:Cucumber-js支持 Chutzpah,但它正在进行中.
(Chutzpah被转移到github,所以问题丢失了)
一个新的Chutzpah功能请求在github上为cucumber-js支持
"支持Cucumber.js正被添加到流行的IDE中,如Jetbrains Webstorm 8和Visual Studio."
我计划重用VS Load Test的现有Specflow场景(目前用于验收和自动测试),以避免重复和额外的工作.Specflow适用于那些测试,因为它运行它们一次,但是在Load测试的上下文中,当它执行每个Specflow场景多次并且并行它会遇到问题和错误并且用户数量更多时会得到更多
这些错误可能会导致部分测试失败,最终会产生不正确的测试结果,例如使用一个Specflow场景作为测试场景,负载测试为20个用户,时间段为2分钟,可能导致50个类似于下面的错误.因此测试结果显示特定场景执行200次,其中150次通过,50次失败测试,失败是由Specflow错误引起的.在负载测试的上下文中,由于测试本身存在问题,因此该结果完全错误且不正确.
错误信息:
ScenarioTearDown threw exception. System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object.
TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.HandleBlockSwitch(ScenarioBlock block)
TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance) TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.Step(StepDefinitionKeyword stepDefinitionKeyword, String keyword, String text, String multilineTextArg, Table tableArg)
TechTalk.SpecFlow.TestRunner.Then(String text, String multilineTextArg, Table tableArg, String keyword)
Run Code Online (Sandbox Code Playgroud)
经过一些调查后,似乎Specflow无法生成和运行相同的方案并行导致此冲突并且未通过一些测试但我也对此有一些疑问,并试图查看是否有任何解决方法或如果我遗漏任何东西并想知道是否Specflow场景可以用于负载测试吗?
我一直在使用SpecFlow,没有使用"但是"逻辑.
考虑以下情况:
Scenario: Kiran logs into the system but doesn't click remember me
Given I have a username of 'Kiran'
And a password of 'password'
When I chose login
But I don't chose remember me
Then I should be logged in
And Taken to the home screen
But My username should not be remembered
Run Code Online (Sandbox Code Playgroud)
难道"but"步骤不能与"和"互换吗?
使用"但是"有什么好处吗?
我是否正确地认为这纯粹是为了可读性目的?
我期待听到你对此的看法.
非常感谢,Kiran
不幸的是,我有一个 Specflow 测试在本地通过,但它在 VSO Build vNext 服务器上失败了,我真的需要在测试运行期间查看详细信息,以便弄清楚发生了什么。
但是我正在努力尝试ITestOutputHelper像这样注入Specflow 绑定
public SomeSteps(ITestOutputHelper outputHelper)
但 Specflow 抱怨消息
BoDi.ObjectContainerException Interface cannot be resolved: Xunit.Abstractions.ITestOutputHelper (resolution path: ...)
在 Specflow 测试期间如何查看日志和查看输出?
我已经在 Specflow 2.0、nUnit 3.X、TeamCity 和 Visual Studio 2013 中编写了自动化测试。我试图并行运行测试,但它们失败了,因为代码使用静态类/对象。
在 Specflow 网站上,建议使用PARALLEL EXECUTION WITH MEMORY (APPDOMAIN) ISOLATION运行线程安全测试(如果架构依赖于静态状态) http://www.specflow.org/documentation/Parallel-Execution/
但是没有关于如何做到这一点的信息,甚至谷歌搜索我也找不到任何相关文章。
如果有人能帮助我了解我们如何做到这一点,我真的很感激。
谢谢你的帮助,萨蒂
specflow ×10
gherkin ×3
bdd ×2
c# ×2
cucumber ×2
appdomain ×1
cucumberjs ×1
load-testing ×1
nunit-3.0 ×1
syntax ×1
unit-testing ×1
xunit ×1
xunit2 ×1