4

So it's my first time with JBehave and I'm trying to create the first JBehave in the project but it currently appears that the test doesn't execute the steps. In the end the test says that all test cases went through without any problems but in fact they are not executed at all. I set break points in every step method and my debugger doesn't stop me at all not to mention the exceptions that these steps currently throw.

This is my scenario:

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'

the steps:

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

and the test executor:

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

Any idea what is wrong with it?

Kamil Janowski
  • 1,872
  • 2
  • 21
  • 43
  • If the test finds your .story file, it should log something like this: "Running story bdd/users/user_registration.story" Does this appear in your log? – Kristof Jul 20 '15 at 14:54

1 Answers1

1

I'm not sure if it is just simple formatting issue in stackoverflow, but i can see, that you indented your steps in your story file with four whitespaces. I think JBehave will not find the steps this way.

So, your .story file should look like this:

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'
Kristof
  • 249
  • 2
  • 7
  • 1
    Don't worry. The test is ok. I can run it and it gets executed just fine. The problem occurs only when I try to do the "test aggregate" as opposed to just "test" as the spring boot server does not start (but it does start when I do just the "gradle test") – Kamil Janowski Jul 20 '15 at 16:21