nicwortel/behat-unused-step-definitions-extension

A Behat extension that detects unused step definitions

v1.1.1 2023-09-29 15:28 UTC

This package is auto-updated.

Last update: 2024-04-29 16:42:23 UTC


README

Do you have a large Behat test suite? Would you like to check your feature contexts for unused step definitions? This Behat extension detects and reports step definitions that are not being used in any of your *.feature files.

License Required PHP version Current version

Screenshot

Installation

composer require --dev nicwortel/behat-unused-step-definitions-extension

Activate the extension in your behat.yml:

default:
  extensions:
    NicWortel\BehatUnusedStepDefinitionsExtension\Extension: ~

Usage

After following the installation steps as documented above, simply run Behat. Instead of actually executing the tests, a dry run will be enough to collect information about unused step definitions:

vendor/bin/behat --dry-run

Note that if you have multiple suites, the unused step definitions will be listed per suite after the suite has finished.

Filtering the results

There are projects where it's important to avoid some step definitions to be detected. For instance, when a project wants to avoid scanning unused step definitions from the third-party packages/libraries and show only results from the custom code. The extension allows to configure a regular expression filter in the behat.yml configuration file. The filter will only allow definitions whose context class name satisfies the regular expression:

default:
  extensions:
    NicWortel\BehatUnusedStepDefinitionsExtension\Extension:
      filter: '#\\MyProject\\Behat\\Contexts#'

In this example only unused step definitions from classes with the namespace containing \MyProject\Behat\Contexts will be outputted.

Extending

By default, the extension uses the unused_step_definitions_printer printer, shipped in the package. The printer displays the list of unused step definitions in the console. Third-party Behat extension might provide different printers (e.g. one may build a text file with the list of unused step definitions). A custom printer should be defined as a container service and should implement the \NicWortel\BehatUnusedStepDefinitionsExtension\UnusedStepDefinitionsPrinter interface. Using a custom printer is possible by providing its service ID in the behat.yml configuration file:

default:
  extensions:
    NicWortel\BehatUnusedStepDefinitionsExtension\Extension:
      printer: my_custom_printer