I'm trying to use BDD in a very simple way, in order to minimize the amount of Java code. I want to create exactly two files, one is my story:
Given user is named "John Doe"
And user is authenticated
When user changes his password to "a1b2c3"
Then user password equals to "a1b2c3"
Next, I create a Java class:
public class UserManipulator {
@Given("$user is named $name")
public User shouldExistOrBeCreated(String name) {
User user = //...
return user;
}
@Given("$user is authenticated")
public void shouldBeLoggedIn() {
// ...
}
@When("$user changes his password to $pwd")
public void shouldChangePassword(User user, String pwd) {
// ...
}
@Then("$user password equals to $pwd")
public void shouldHaveThisPassword(User user, String pwd) {
assertEquals(user.getPassword(), pwd);
}
}
And that's it. I don't want to have any more files, any more unit tests. I want some BDD-framework to find my story file, parse all my Java files, and run them one by one. Is it possible to achieve?
ps. What is important here is a possible reuse of Java methods in my other stories. For example, this is the story no.2:
Given user is named "Michael Doe" <-- reuse
When user adds $100.00 to his account
Then user account balance is $100.00