故事讲述后可以开车吗? 1 JBhave步骤? [英] Can one Given When Then story drive > 1 JBhave Steps?

查看:275
本文介绍了故事讲述后可以开车吗? 1 JBhave步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个.story文件,并带有何时给定"(GWT).

I've created a .story file with a Given When Then (GWT).

Contact_List.story 场景:发现联系人 鉴于我有朋友的联系清单 当其中之一在线时 然后那个朋友会显示在列表中

Contact_List.story Scenario: Discover Contact Given I've a contact list of friends When one of them is online Then that friend is displayed in a list

我想进行两个级别的测试(一堆快速服务层测试和一些UI测试).因此,我使用完全相同的GWT语言创建了以下代码:

I'd like to have two levels of testing (a bunch of fast service layer tests, and a few UI tests). So I created the following using the exact same GWT language:

ServiceSteps.java

ServiceSteps.java

@Given("I've a contact list of friends")
...

UISteps.java

UISteps.java

@Given("I've a contact list of friends")
....

,并配置了JBehave以同时使用它们: RunBDDTests.java

And Configured JBehave to use both of them: RunBDDTests.java

...
@Override
public InjectableStepsFactory stepsFactory() {       
    // varargs, can have more that one steps classes
    return new InstanceStepsFactory(configuration(), new ServiceSteps(), new UISteps());
}
...

但是,当在JUNit中运行它时,每次我运行测试时,选择哪个Steps类都是随机的.

But, when running this in JUNit, each time I run the tests, it's random as to which Steps class it selects.

如何让它每次都运行两个步骤,以便一个.story文件驱动器> 1个步骤类?

How to have it run both steps each time so that one .story file drives > 1 steps class?

推荐答案

这是由配置组织的.用JBehave的话来说,Configuration是告诉JBehave框架如何将* .stories与* Steps.java关联的类.在问题示例中,这是RunBDDTests.java.将两个步骤与一个GWT场景相关联的一个选项是创建两个配置,一个用于服务步骤,一个用于UI步骤:

This is organized by the Configuration. In JBehave parlance, the Configuration is the class that tells the JBehave framework how to associate *.stories with *Steps.java. In the questioniers example, this is RunBDDTests.java. One option that will associate two steps with a single GWT scenario is to create two Configurations, one for the Service steps and one for the UI steps:

ServiceConfiguration.java

public class ServiceConfiguration extends JUnitStories
{
 @Override
 public InjectableStepsFactory stepsFactory() {       

    return new InstanceStepsFactory(configuration(), new ServiceSteps()); // <- note steps class
 }

@Override
protected List<String> storyPaths() {

    return new StoryFinder().findPaths(CodeLocations.codeLocationFromClass(this.getClass()), "**/Contact_List.story", "");  //<- note story file name
}
}

UIConfiguration.java

UIConfiguration.java

public class UIConfiguration extends JUnitStories
{
    @Override
    public InjectableStepsFactory stepsFactory() {              
      return new InstanceStepsFactory(configuration(), new UISteps()); // <- note steps class
    }

@Override
protected List<String> storyPaths() {       
  return new StoryFinder().findPaths(CodeLocations.codeLocationFromClass(this.getClass()), "**/Contact_List.story", "");  //<- note story file name
}
}

以上两种配置将针对一个.story运行两个不同的步骤文件.

The above two configurations will run two different step files against one .story.

这篇关于故事讲述后可以开车吗? 1 JBhave步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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