If you follow automation testing best practices religiously it will eventually decrease rework. Nowadays, BDD frameworks have strong automation testing user base. BDD framework enables effective collaboration and automation. If your team is following Agile methodology, then make sure you automate Acceptance Criteria of each story within the sprint. The reason being if any automation test script is being developed with effective collaboration, it will produce high-quality output. Let’s say you have missed to automate a couple of stories in the current sprint, then the non-automated acceptance criteria becomes a technical debt and you may face difficulties to connect with your team members to discuss about old sprint stories.
If you are automating existing regression tests pack, you can use BDD framework only for automation without collaboration. Writing BDD test scenarios is an art. None of your team can understand if a Gherkin scenario is too long. Following best practices is an essential for successful automation testing with BDD.
Feature Template
Feature: [One line describing the story] [Optional — Feature description] Scenario: [One line describing the scenario] Given [context] And [some more context]… When [event] Then [outcome] And [another outcome]…
BDD Scenario Best Practices
- Given-When-Then should be in sequence.
- Each scenario should ideally have only one ‘When’ clause that clearly points to the purpose of the test.
- Use past tense for ‘Given’ clauses, present tense for ‘When’ and future tense for ‘Then’.
- Use ‘And’ clause to add multiple Given and Then steps.
- Put scenarios prerequisite steps in ‘Background’. Note: If the prerequisite steps are more technical, then use Before hook.
- Scenarios should be more functionality oriented rather than UI/UX actions.
- You can also write BDD Styled Acceptance Criteria for web services. However, you need to ensure it is understood by the product owner.
- Write scenarios after talking to business people.
- Use declarative steps rather than imperative.
Declarative
Given I pass the header information for SSN When the client request the URL with data Then the response code should be 200
Imperative
Given I pass the header information for SSN When client request POST "<ServiceURL>" with json data "<RequestFile>" Then the response code should be 200 And the SSNcached result should be same as valid transaction response "<ResponseFile>"
Tagging
Grouping test scenarios from different features is must. In order to select the tests for different execution types, tagging is important. Nowadays, we have many test cases managements plugins for Jira. Updating automated test execution result in Jira is vital. Managing manual and automated executions result in test case management tool is helpful to collect test metrics and improve the test coverage. As one of the leading test automation companies, we tag BDD scenarios with Test ID, environment (qa, stage, 7 prod), and testing purpose (Smoke, Integration & regression). Using Test ID, we can push the automated test execution status in test case management tool.
Feature Narrative Description
Feature: Title (one line describing the story) Narrative Description: As a [role], I want
Step Definitions dos and don’ts
- Don’t call a step definition method from another method.
- Never hard code any test data in step definition.
- Learn how regular expression is used to match a Gherkin step and a Step Definition method.
- Chain the assertions to enable code readability.
assertThat(fellowshipOfTheRing).filteredOn( character -> character.getName().contains("o") ) .containsOnly(aragorn, frodo, legolas, boromir);
Use Cucumber Lambda expressions to simplify the step definitions.
Given("I login as (.*)$",(String name)-> System.out.println(name));
Reporting
BDD Reporting is important to trouble-shoot the failures and collect test automation metrics. You can use Serenity BDD reporting, ExtentReporter for BDD, Report Portal, and Allure Reporting.
In Conclusion
We, as a test automation services company, use Cucumber, Behave, SpecFlow, and Serenity BDD frameworks for our automation testing projects. Following automation testing best practices has helped us to deliver high-quality test automation scripts to our clients with precision. We suggest that you prepare a training plan for your automation testers and make them understand how anti-patterns impact test automation. Writing BDD scenarios which are too long will not add value to the team and it increases script maintenance. If your team is comfortable using DSL, then the output of your test automation scripting will be concise, which will enable the effective collaboration between Developers, Testers, and Business.
Comments(0)