JBehave似乎没有执行测试

时间:2015-07-14 16:33:03

标签: java jbehave

所以这是我第一次使用JBehave而我正在尝试在项目中创建第一个JBehave,但目前似乎测试没有执行这些步骤。 最后,测试表明所有测试用例都没有遇到任何问题,但事实上它们根本没有执行。我在每个步骤方法中设置了断点,我的调试器根本不会阻止我,更不用说这些步骤当前抛出的异常。

这是我的情景:

Narrative:
In order for the user to start using the application, he first needs to register and log in

Scenario: Successful registration
    Given a user with email 'test@test.com'
    When the user specifies password 'aaaaaa'
    Then the user should be successfully registered with email 'test@test.com' and hashed password 'aaaaaa'

步骤:

public class UserRegistrationSteps extends Steps {

    @Given("a user with email '$email'")
    public void addNewUser(@Named("email") String email) {
        User u = new User();
        u.setEmail(email);
        throw new RuntimeException("test");
    }

    @When("the user specifies password '$password'")
    public void setPassword(@Named("password") String password) {
        System.out.println("test");
        throw new RuntimeException("test");
    }

    @Then("the user should be successfully registered with email '$email' and hashed password '$password'")
    public void verifySuccessfulRegistration(@Named("email") String email, @Named("password") String password) {
        System.out.println("test");
        throw new RuntimeException("test");
    }
}

和测试执行者:

public class UserRegistrationTest extends JUnitStories {

    public UserRegistrationTest() {
        super();
        this.configuredEmbedder().candidateSteps().add(new UserRegistrationSteps());
    }

    @Override
    protected List<String> storyPaths() {
        return Arrays.asList("bdd/users/user_registration.story");
    }
}

知道它有什么问题吗?

1 个答案:

答案 0 :(得分:1)

我不确定它是否只是stackoverflow中的简单格式化问题,但我可以看到,您在故事文件中缩进了四个空格的步骤。我认为JBehave不会以这种方式找到这些步骤。

因此,您的.story文件应如下所示:

Narrative:
In order for the user to start using the application, he first needs to register and log in

Scenario: Successful registration
Given a user with email 'test@test.com'
When the user specifies password 'aaaaaa'
Then the user should be successfully registered with email 'test@test.com' and hashed password 'aaaaaa'