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
Every resource in the software development phase can contribute to the BDD framework. Due to its easy concept of layman text in the form of feature file allows the stakeholders of technical resources to write the scenarios in Gherkin language using the user stories. The compatibility of the plain text helps to gain maximum coverage on testing.
A user story has a slightly different structure to your BDD. Your user story should comprise the following: As a new user (John), I can register a new account on the homepage so that I can access LinkedIn. If you have multiple scenarios, you’d add these after Scenario 1 in a sequence.
Your BDD scenarios should form part of 1 specification. This includes both the user story and the scenarios. So, for example, if you’re writing a user story in Jira or some other beloved backlog management tool you could structure your specification in Jira in the following order:
Using Scenarios – BDD is designed to speed up the development process. Everyone involved in development relies upon the same scenarios. Scenarios are requirements, acceptance criteria, test cases, and test scripts all in one; there is no need to write any other artifact.
You want to have a look at:
Also, this presentation on BDD in Java and Groovy could be of interest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With