How to load history file from another folder in JBehave

I need to have the mystory.story and MyStory.java file in different folders. Below is my configuration,

@Override public Configuration configuration() { return new MostUsefulConfiguration() // where to find the stories .useStoryLoader(new LoadFromClasspath(this.getClass())) // CONSOLE and TXT reporting .useStoryReporterBuilder( new StoryReporterBuilder().withDefaultFormats() .withFormats(Format.CONSOLE, Format.HTML)); } // Here we specify the steps classes @Override public List<CandidateSteps> candidateSteps() { // varargs, can have more that one steps classes return new InstanceStepsFactory(configuration(), new SurveySteps()) .createCandidateSteps(); } 

That is, I need to use the folder structure as

  test |_config |_MyStory.java |_stories |_my_Story.story 

instead of <

  test |_MyStory.java |_my_Story.story 

How can i achieve this?

+4
source share
2 answers

I assume that you are using JUnitStory . I think the only thing you need to do is overlay the class path on both directories: test/config and test/stories . The default narrator is org.jbehave.core.io.UnderscoredCamelCaseResolver , this will create a history path like "org.jbehave.core.ICanLogin.java" -> "org/jbehave/core/i_can_login.story" and it will be loaded from using org.jbehave.core.io.LoadFromClasspath because it is the default resource loader. Since the src/stories directory is in the classpath, the resource loader will find it. Please note that this requires that classes and stories be placed in the same “package”, that is, if the class is com.foo.Bar (placed in src/config ), you must put the corresponding story in com/foo/Bar.story (in src/stories ). This is like splitting resource files and java files into separate folders.

+1
source

You can override the default history path resolver, for example:

 @Override public Configuration configuration() { return new MostUsefulConfiguration() .useStoryPathResolver(new StoryPathResolver() { @Override public String resolve(Class<? extends Embeddable> embeddableClass) { return "_stories/_my_Story.story"; } }) } 

(Of course, it's better to create somewhere outside the class and use it here, rather than anonymously). But keep in mind that if you do this, you also need to explicitly specify the name of the history file, reuse somehow the jbehave functionality that converts "MyClass" to "my_class" or creates your own strategy.

+1
source

Source: https://habr.com/ru/post/1495519/


All Articles