behat
Run Behavior-Driven Development (BDD) tests
TLDR
Initialize a new Behat project
Run all tests
Run all tests from the specified suite
Run tests with a specific output formatter
Run tests and output results to a file
List the definitions in your test suites
SYNOPSIS
behat [options] [features_path]
PARAMETERS
--init
Initializes a new Behat project.
--config
Specify the configuration file to use.
--profile
Select a specific profile from the configuration file.
--format
Specify the output format (e.g., pretty, progress, junit).
--out
Specify the output path.
--name
Filter scenarios by name using a regular expression.
--tags
Filter scenarios by tags (e.g., @tag1,@tag2).
--cache
Enable cache for faster test execution.
--stop-on-failure
Stop execution on first failure.
--help
Displays help information.
--version
Displays the Behat version.
DESCRIPTION
Behat is an open-source Behavior-Driven Development (BDD) framework for PHP.
It enables you to describe the expected behavior of your application using human-readable language called Gherkin. These descriptions, called features, are composed of scenarios that specify how the application should respond to particular inputs or actions.
Behat then executes these scenarios and reports whether the application behaves as expected. This promotes collaboration between developers, testers, and stakeholders, ensuring a shared understanding of the application's functionality and requirements.
Behat allows you to write integration and acceptance tests. It helps you to ensure that your application is working as expected from the user's perspective. It's particularly useful for testing web applications, APIs, and other complex systems. Behat relies on creating feature files using gherkin syntax which describe expected behaviors.
The behat executable parses those feature files and executes the steps within those scenarios in order. It is a powerful tool for building robust and testable applications.
CAVEATS
Behat requires a PHP environment and a configuration file (behat.yml or behat.yml.dist) to run effectively. Writing effective Behat tests requires a good understanding of BDD principles and Gherkin syntax. Careful consideration should be given to defining clear and concise scenarios that accurately represent the desired behavior of the application.
CONFIGURATION FILES
Behat uses a configuration file (behat.yml or behat.yml.dist) to define settings such as the features path, step definitions, and other environment-specific configurations. This file is crucial for customizing Behat's behavior and integrating it with your project.
STEP DEFINITIONS
Step definitions are PHP functions that are associated with steps in your Gherkin scenarios. They contain the actual code that interacts with your application to perform the actions described in the steps and verify the expected outcomes. Creating well-defined and reusable step definitions is essential for writing maintainable Behat tests.
GHERKIN SYNTAX
Behat utilizes the Gherkin syntax within the feature files. Gherkin defines a simple and easy to read language which describes the behavior of a component. The most important keywords are: Feature, Scenario, Given, When, Then, And, But.
HISTORY
Behat was created to provide a BDD framework for PHP projects, inspired by similar tools like Cucumber in Ruby. It has evolved over time to support various PHP versions and testing methodologies. It became one of the defacto standard for integration testing in PHP applications. Active community support and regular updates have contributed to its widespread adoption in the PHP development community.
SEE ALSO
phpunit(1)