根据其他功能具有specflow功能是否有效? [英] Is it valid to have specflow features depending on other features?
问题描述
我想按照以下内容编写验收测试
I want to write an acceptance test along the lines of
given the first test has run
when I do this new test
then this new test passes
这是因为第一次测试会将数据保留为有效状态,以执行下一次测试
This is because the first test will leave the data in a valid state to perform the next test
我可以在Specflow中做到这一点吗?
Can I do this in Specflow?
推荐答案
是的,您可以在specflow中执行此操作,但要注意一点.此方法将不会运行一个方案,然后再运行另一个方案,它将自己运行第一个方案,然后从属方案将再次运行第一个方案,然后再运行第二个方案.这些顺序可能不确定.一旦编写了从属方案,我们就通过第一个方案@ignore
避免了这个问题.由于第二个方案始终会运行第一个方案,因此@ignore
d并不重要,因为第一个方案中的任何故障都会触发第二个方案中的故障.
yes you can do this in specflow, but with a slight caveat. this approach will not run one scenario, then run the other, it will run the first scenario on its own, then the dependent scenario will run the first scenario again followed by the second scenario. The order of these may not be deterministic. We have avoided this issue by @ignore
the first scenario once the dependent scenario is written. As the second scenario always runs the first scenario anyway it doesn't matter that its @ignore
d, as any failure in the first scenario will trigger a failure in the second scenario.
我们为实现这一目标所做的工作大致如下:
What we have done to achieve this is along these lines:
Scenario: Some base scenario
Given some condition
When some action
Then some result
然后稍后在另一个功能中:
then later in another feature:
Scenario: Some dependant scenario
Given some base scenario has happened
And some other condition
When some other action
Then some other result
键在步骤Given some base scenario has happened
如果您这样定义此步骤:
if you define this step like this:
[Given("some base scenario has happened")]
public void SomeBaseScenarioHasHappened()
{
Given("some condition");
When("some action");
Then("some result");
}
您需要确保保存步骤定义的类是从specflow中的基类Steps
派生的,以便访问Given
,When
和Then
方法:
you need to ensure that your class which holds your step definitions derives from the base Steps
class in specflow to get access to the Given
, When
and Then
methods:
[Binding]
public class MyStepClass: Steps
您可以在 specflow Wiki
这篇关于根据其他功能具有specflow功能是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!