Mutation Testing with Infection

Overview

Mutation testing is the least common and most misunderstood type of testing. With mutation testing, the code under test is changed to create a faulty version called a mutant. You then run the mutant code through a suite of test cases, which should produce new test case failures. If no new failures appear, the test suite most likely does not exercise the code path containing the mutated code, which means the code isn't fully tested.

Performing mutation testing with Pest couldn't be easier as the most popular mutation testing framework - Infection - includes out-of-the-box support for Pest.

Installation

Requirements: Pest 1.2+, Infection 0.23+

First, install Infection via the Composer package manager:

1composer require infection/infection --dev

Then, you can run Infection directly from the command line:

1./vendor/bin/infection --test-framework=pest --show-mutations
2
3# With XDebug
4XDEBUG_MODE=coverage ./vendor/bin/infection --test-framework=pest --show-mutations

Next section: Faker Plugin →