Can one Given When Then story drive > 1 JBhave Steps?

為{幸葍}努か 提交于 2019-12-02 06:52:23

问题


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

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

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

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

UISteps.java

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

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());
}
...

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

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


回答1:


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

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
}
}

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



来源:https://stackoverflow.com/questions/16525464/can-one-given-when-then-story-drive-1-jbhave-steps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!