Test Framework¶
A test framework is a library or tool that provides the infrastructure for writing, organising, and running automated tests. It typically offers assertion helpers, test runners, fixtures, and reporting.
In PHP, the dominant test framework is PHPUnit. Pest is a newer alternative built on top of PHPUnit, offering a more expressive, function-based syntax. Other frameworks include atoum and Codeception.
A test framework does not dictate what to test; it provides the mechanics to express and execute tests repeatably, integrate with CI pipelines, and produce machine-readable reports, such as JUnit XML, code coverage, etc.
<?php
// PHPUnit example
use PHPUnit\Framework\TestCase;
class MathTest extends TestCase {
public function testAdd(): void {
$this->assertSame(4, 2 + 2);
}
}
?>
See also PHPUnit, Pest and Codeception.
Related : Test, PHPunit, Continuous Integration (CI), Code Coverage