Behat test in Drupal 8
Problem:
I want to verify my commit doesnt break the deployment and it works as expected.
We can do the manual testing after the deployment is completed. But,
- Manual Testing/Regression testing is expensive.
- Time consuming.
- More chances for reopening closed tickets.
How do you know when your feature actually working or done ?
- Check Requirements and compare?
- Check Acceptance criteria ?
- Stakeholder confirms it ?
- Developer confirms it or QA verified it ?
Solution:
- Automated testing
- Code that tests the code.
- Test after each deployment automatically and make sure it doesnt break the site.
Automated testing is the answer to the all the questions. Behaviour Driver Development with Behat is the proposed solution.
What is Behat ?
“Behat is a tool to test the behaviour of your application, described in a special language called Gherkin language.”
BDD with Behat, How it works ?
Feature files
All tests are based on Feature file (.feature)
Features are user story which will describe need, benefit and beneficiary.
example:
In order to verify admin page access
As an administrator user
I need to login as administrator.
Background:
If the user or page is same we can use background.
Scenarios.
Requirements (Given)
Actions (When)
Verification of Outcomes (Then)
Multiple (And and But)
Steps
Step Definitions are defined in Drupal extensions and we can reuse.
Get the definitions using behat -di
Contexts
Default FeatureContext Class
Mink
Clicking links
Fill in the form.
Wait for animation.
Drupal Extensions Drivers
Blackbox Driver
Drush Driver
Drupal API Driver