Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jbehave-@beforeStories不';行不通_Java_Configuration_Annotations_Jbehave - Fatal编程技术网

Java Jbehave-@beforeStories不';行不通

Java Jbehave-@beforeStories不';行不通,java,configuration,annotations,jbehave,Java,Configuration,Annotations,Jbehave,我的故事文件: Narrative: In order to document all the business logic requests As a user I want to work with documents Scenario: Basic new document creation Given a user name Micky Mouse When new document created Then the document should named new documen

我的故事文件:

Narrative:
In order to document all the business logic requests
As a user
I want to work with documents

Scenario: Basic new document creation
Given a user  name Micky Mouse
When new document created
Then the document should named new document
And the document status should be NEW
我的代码:

public class DocStories extends JUnitStory {

    @Override
    public Configuration configuration() {
        return new MostUsefulConfiguration().useStoryLoader(
                new LoadFromClasspath(getClass().getClassLoader()))
                .useStoryReporterBuilder(
                        new StoryReporterBuilder().withFormats(Format.STATS,
                                Format.HTML, Format.CONSOLE, Format.TXT));

    }

    @Override
    public List<CandidateSteps> candidateSteps() {
        return new InstanceStepsFactory(configuration(), new DocSteps())
                .createCandidateSteps();
    }

    @Override
    @Test
    public void run() throws Throwable {
        try {
            super.run();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
公共类DocStory扩展JUnitStory{
@凌驾
公共配置(){
返回新的mostuseveConfiguration().useStoryLoader(
新建LoadFromClasspath(getClass().getClassLoader())
.useStoryReporterBuilder(
新的StoryReporterBuilder().withFormats(Format.STATS,
Format.HTML、Format.CONSOLE、Format.TXT);
}
@凌驾
公开名单{
返回新InstanceStepsFactory(配置(),新DocSteps())
.createCandidateSteps();
}
@凌驾
@试验
public void run()抛出可丢弃的{
试一试{
super.run();
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
}
在课堂上使用我的步骤:

public class DocSteps {
    private final Map<String, User> users = new HashMap<String, User>();
    private final DocManager manager = new DocManager();

    private User activeUser;
    private Document activeDocument;
    private boolean approvedResult;

     *****************BEFORE***************//
     @BeforeStories
     private void initUsers() {
     users.put("Micky Mouse", new User("Micky Mouse", UserRole.ANALYST));
     users.put("Donald Duck", new User("Donald Duck", UserRole.BCR_LEADER));
     System.out.println("Check this out" + users.toString());
     }

    // **********steps*************//
@Given("a user name $userName")
public void connectUser(String userName) {
    // in the real world - it will get the user from the db
    System.out.println(userName);
    activeUser = new User(userName, UserRole.ANALYST);
    // System.out.println(activeDocument.getName());
}

@Given("a new document")
@When("new document created")
public void createDocument() {
    activeDocument = new Document();
}

@Given("a document with content")
public void createDocWithContect() {
    createDocument();
    activeDocument.setContent("this is a document");
}

@Then("the document should named $docName")
@Alias("the document name should be $docName")
public void documentNameShouldBe(String docName) {
    Assert.assertEquals(docName, activeDocument.getName());
}

@Then("the document status should be $status")
public void documentStatusShouldBe(String status) {
    DocStatus docStatus = DocStatus.valueOf(status);
    Assert.assertThat(activeDocument.getStatus(),
            Matchers.equalTo(docStatus));
}

    // *****************AFTER***************//
    @AfterScenario
    public void clean() {
        activeUser = null;
        activeDocument = null;
        approvedResult = false;
    }

}
公共类DocSteps{
私有最终映射用户=新HashMap();
私有最终DocManager=新DocManager();
私有用户;主动用户;
私人文件;
私有布尔批准结果;
*****************以前***************//
@森林学
私有void initUsers(){
put(“米老鼠”,新用户(“米老鼠”,UserRole.ANALYST));
users.put(“唐老鸭”,新用户(“唐老鸭”,UserRole.BCR_LEADER));
System.out.println(“Check this out”+users.toString());
}
//**********步骤*************//
@给定(“用户名$userName”)
公共用户(字符串用户名){
//在现实世界中,它将从数据库中获取用户
System.out.println(用户名);
activeUser=新用户(用户名,UserRole.ANALYST);
//System.out.println(activeDocument.getName());
}
@给定(“新文件”)
@何时(“创建新文档”)
公共文档(){
activeDocument=新文档();
}
@给定(“包含内容的文档”)
public void createDocWithContect(){
createDocument();
setContent(“这是一个文档”);
}
@然后(“文档应命名为$docName”)
@别名(“文档名称应为$docName”)
public void documentNameShouldBe(字符串docName){
Assert.assertEquals(docName,activeDocument.getName());
}
@然后(“文档状态应为$status”)
公共作废文档状态应为(字符串状态){
DocStatus DocStatus=DocStatus.valueOf(状态);
Assert.assertThat(activeDocument.getStatus(),
Matchers.equalTo(docStatus));
}
//**********************之后***************//
@赛后
公共空间清洁(){
activeUser=null;
activeDocument=null;
approvedResult=假;
}
}
不执行带有“before和after”故事注释的方法。
enum
转换器也不工作


我的配置有什么问题(我假设它是我的配置)?

问题在于您的方法initUsers是私有的。只需将其公开,JBehave引擎即可看到:

@BeforeStories
public void initUsers() {
//...
}

请添加相应的.story文件-我有一个预感