我需要将 mystory.story 文件和 MyStory.java 放在不同的文件夹中。下面是我的配置,
@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();
}
那是我需要使用文件夹结构作为
test
|_config
|_MyStory.java
|_stories
|_my_Story.story
而不是,
test
|_MyStory.java
|_my_Story.story
我怎样才能实现它?
最佳答案
我假设您使用 JUnitStory
。
我认为您唯一需要做的就是将两个目录放在类路径中:test/config
和 test/stories
。默认的故事解析器是 org.jbehave.core.io.UnderscoredCamelCaseResolver
这将创建一个故事路径,如 "org.jbehave.core.ICanLogin.java"-> "org/jbehave/core/i_can_login.story"
,这将使用 org.jbehave.core.io.LoadFromClasspath
加载,因为这是默认的资源加载器。由于 src/stories
目录在类路径中,资源加载器会找到它。请注意,这需要类和故事放在同一个“包”中,也就是说,如果类是 com.foo.Bar
(放在 src/config
中)然后你必须将相应的故事放入 com/foo/Bar.story
(在 src/stories
中)。这类似于将资源文件和 java 文件分离到单独的文件夹中。
关于java - 我如何从 JBehave 中的不同文件夹加载故事文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18079313/