java - Jbehave - @beforeStories 不起作用

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

}

在类里面我的步骤:

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

}

带有“之前和之后”故事注释的方法不会被执行。 enum 转换器也不起作用。

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

最佳答案

问题是您的方法 initUsers 是私有(private)的。只需将其公开,JBehave 引擎就可以看到它:

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

关于java - Jbehave - @beforeStories 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14308363/

相关文章:

linux - 如何在多用户环境中设置 Eclipse 的全局首选项?

configuration - 如何配置 Xcode 来编译不支持的语言,例如弗兰语言?

java - @Value 在 SpEL 中如何工作?

c++ - 使用 gcc 插件获取类注释

javascript - AngularJS XSRF 策略不支持 cookie 路径

java - 如何为 Java 创建 REST 客户端?

Java,Jboss,如何加载jboss类路径中的属性文件

java - 开源 ETL 框架

java - RoundingMode HALF_EVEN 类似于用于 float 的舍入策略

r - 将相关性测试结果添加到 ggplot