Below are some guidelines for developing and maintaining the Behat steps.
A consistent steps format is essential for the readability and maintainability of tests. Follow these guidelines:
-
General Guidelines:
- Avoid using regular expressions to define a step definition. Use tuple format instead for better clarity and maintainability.
- Use descriptive placeholder names to help users quickly understand the
expected value:
content_typeinstead oftype. - Use
the followingfor tabled content. - For anything identified by a property, use
with:Then the link : link with the title :title should exist - Avoid optional words like
(the|a). Provide a single form instead to ensure consistency. - Omit unnecessary suffixes like
on the pagesince it is implied. - All method names should begin with the trait name:
userAssertHasRoles()forUserTrait.
-
Given:- Defines test prerequisites—conditions or data that must exist before the test runs.
- Use words like
existsorhave. - Avoid using
shouldorshould not(these are reserved for assertions). - Refrain from using
Given I(reserved for actions).
-
When:- Describes an action and must contain an action verb.
- Use the format
When I <verb>.
-
Then:- Specifies assertions and expectations.
- Use
shouldandshould notto clearly indicate assertions. - Start the step with the entity being asserted, e.g.,
Then the link with a title :title exists. - Avoid using
Then I. - Methods should include the
Assertprefix, e.g.,userAssertHasRoles().
We have some automated check for the steps format.
Run ahoy lint-docs to validate the format of the steps.
- Existence assertions:
- Singular subjects →
ExistsorNotExists(e.g.,fieldAssertExists(),vocabularyAssertNotExists()) - Plural subjects →
ExistorNotExist(e.g.,termsAssertExist())
- Singular subjects →
- Contains assertions: Always use
ContainsorNotContains(e.g.,xmlAssertElementContains(),headerAssertNotContains()) - Never use "DoesNot" or "DoNot" patterns - use "Not" prefix directly
Install Docker, Pygmy, Ahoy and shut down local web services (Apache/Nginx, MAMP etc)
- Checkout project repository in one of the supported Docker directories.
pygmy upahoy build- Access built site at http://behat-steps.docker.amazee.io/
Use ahoy --help to see the list of available commands.
There are two types of tests in this repository: unit tests and Behat tests.
Unit tests are run using PHPUnit installed in the root of the repository and are independent of the Drupal version. This allows us to use the latest features of PHPUnit.
ahoy test-unit # Run all unit tests
ahoy test-unit-coverage # Run tests with code coverageBehat tests are used as functional/integration tests to validate the functionality of the traits. These Behat tests run in the same way they would be run in your project: traits are included into FeatureContext.php and then ran on the pre-configured fixture Drupal site using test features.
Run ahoy build to setup a fixture Drupal site in the build directory.
ahoy test-bdd # Run all Behat tests
ahoy test-bdd path/to/file # Run all Behat scenarios in specific feature file
ahoy test-bdd -- --tags=wip # Run all Behat scenarios tagged with `@wip` tagahoy debug- Set breakpoint
- Run tests with
ahoy test-bdd- your IDE will pickup an incoming debug connection
- Build the fixture site and make the required changes
ahoy drush cex -yahoy update-fixturesto copy configuration changes from build directory to the fixtures directory
The available steps documentation is generated automatically from the source code.
The steps format is validated as well.
ahoy update-docs # Update documentation
ahoy lint-docs # Check documentation for errors