Utilities for Behat 3.x "tips & tricks"

by Carlos Montes //

Article with some tricks that will help us to understand and improve our knowledge about Behat.

 Key commands list for behat

Run the tests with the configuration have given by the yml file

behat --config [path/to/yml]

Example: behat --config sites/default/default.behat.yml


Initialize the feature suite structure inside your project, 

behat --config [path/to/yml] --init

Behat will automatically add all missing pass methods to your FeatureContext class

behat --config [patt/to/yml] --dry-run --append-snippets

We generate a template of a Yml file by default with its specifications, if we also export it, we will quickly have a predefined configuration file.

behat --config-reference
# Example
behat --config-reference > default.behat.yml



We can use the tags that give us Behat to manage which Scenarios we want to execute and which omit
To understand it, here is what is evaluated as Boolean expression in the different cases:

~test,test2: (NOT test) OR test2

~@test,~@test2: (NOT test) OR (NOT test2) which is equivalent to NOT (test AND test2)

~@test&&~@test2: (NOT test) AND (NOT test2)

* The @ in the tag name is optional in all cases: @ `is replaced by an empty string.

#Behat #Behat 3.x #Testing



Drupal developer, Site Builder, Custom module development, Drupal support forums, Contributed Drupal...

Author latest articles

You may also like