2013-08-06 30 views
4

我需要將mystory.story文件和MyStory.java放在不同的文件夾中。下面是我的配置,如何從JBehave中的不同文件夾加載故事文件

@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 

我怎樣才能實現呢?

+0

您是繼承'JunitStories' /'JunitStory'嗎? – Katona

回答

1

我假設你使用JUnitStory。 我認爲你唯一要做的就是把classpath放在兩個目錄中:test/configtest/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文件分隔爲單獨的文件夾類似。

1

您可以覆蓋默認的故事路徑解析,例如:

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

(當然最好是課堂外的地方在此處創建和使用它,而不是匿名)。 但請記住,如果您這樣做,您還需要明確指定故事文件的名稱,以某種方式重用jbehave將「MyClass」轉換爲「my_class」的功能或創建自己的策略。

相關問題