【问题标题】:JBehave doesn't seem to execute the testsJBehave 似乎没有执行测试
【发布时间】:2015-07-20 23:55:42
【问题描述】:

所以这是我第一次使用 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");
    }
}

知道有什么问题吗?

【问题讨论】:

  • 如果测试找到您的 .story 文件,它应该记录如下内容:“Running story bdd/users/user_registration.story” 这是否出现在您的日志中?

标签: java jbehave


【解决方案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'

【讨论】:

  • 别担心。测试没问题。我可以运行它并且它执行得很好。只有当我尝试执行“测试聚合”而不是“测试”时才会出现问题,因为 Spring Boot 服务器没有启动(但它确实在我执行“gradle 测试”时启动)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多