LinuxCommandLibrary

behat

Run Behavior-Driven Development (BDD) tests

TLDR

Initialize a new Behat project

$ behat --init
copy

Run all tests
$ behat
copy

Run all tests from the specified suite
$ behat --suite [suite_name]
copy

Run tests with a specific output formatter
$ behat --format [pretty|progress]
copy

Run tests and output results to a file
$ behat --out [path/to/file]
copy

List the definitions in your test suites
$ behat --definitions
copy

SYNOPSIS

behat [options] [suite| feature [feature ...]]

PARAMETERS

--help, -h
    Display help message and exit

--version, -V
    Print Behat version

--config FILE, -c
    Load behat.yml config from FILE

--format FORMAT, -f
    Output format (progress, junit, html, etc.)

--out FILE, -o
    File/path for format output

--no-colors
    Disable color output

--colors
    Force color output

--stop-on-failure
    Stop on first failed scenario

--tags TAG_EXPR, -t
    Run scenarios matching tag expression (e.g., @foo or @foo&&~@bar)

--exclude-tags TAG_EXPR
    Exclude scenarios matching tag expression

--definitions
    Print available step definitions

--dry-run
    Execute without running steps

--strict
    Fail when undefined steps found

--retry TRIES
    Number of retries for failed scenarios

DESCRIPTION

Behat is an open-source Behavior-Driven Development (BDD) tool for PHP, inspired by Cucumber. It enables writing executable specifications in plain language using Gherkin syntax (Given/When/Then steps). Tests are organized into feature files (.feature) that describe application behavior from a user's perspective.

Behat parses these files, executes steps via custom PHP definitions, and reports results in various formats. It's ideal for agile teams to bridge business stakeholders and developers. Supports contexts for shared functionality, suites for grouping features, and extensions for advanced needs like parallel execution or API mocking.

Installation typically via Composer: composer require --dev behat/behat. Run ./vendor/bin/behat --init to bootstrap. Integrates with Symfony, Drupal, and other PHP frameworks. Emphasizes collaboration with readable tests that double as documentation.

CAVEATS

Requires PHP 7.4+ and Composer; not a native Linux binary—install via composer global require behat/behat or per-project. Feature files must be UTF-8 encoded. Heavy reliance on custom step definitions; poor definitions lead to brittle tests. Performance scales poorly for large suites without extensions.

INSTALLATION

Global: composer global require behat/behat. Project: composer require --dev behat/behat. Init: bin/behat --init.

EXAMPLE USAGE

behat features/ — Run all features.
behat --format=progress --tags=@api — Run API-tagged scenarios.

HISTORY

Created by Konstantin Kudryashov (Everzet) in 2010 as Behat 1.0. Evolved to v2 (2011) with better Gherkin support, v3 (2014) adopting Mink for browser automation and Symfony components. v4 (beta 2023) focuses on modern PHP/Docker. Widely used in Symfony ecosystem; over 3M downloads on Packagist.

SEE ALSO

php(1), composer(1)

Copied to clipboard