A PHPUnit extension that measures and reports test size distribution (Small/Medium/Large).
PHPUnit supports test size classification through #[Small], #[Medium], and #[Large] attributes. This extension analyzes your test suite and reports the distribution of test sizes, helping you maintain a healthy test pyramid.
- PHP 8.1+
- PHPUnit 10.5+ / 11.x / 12.x
composer require --dev twada/phpunit-size-distributionRegister the extension in your phpunit.xml:
<phpunit>
<!-- ... -->
<extensions>
<bootstrap class="Twada\PHPUnitSizeDistribution\TestSizeReporterExtension"/>
</extensions>
</phpunit>Run your tests as usual:
vendor/bin/phpunitAfter test execution, you'll see a report like this:
Test Size Distribution
======================
Small: 5 tests ( 62.5%)
Medium: 1 tests ( 12.5%)
Large: 1 tests ( 12.5%)
None: 1 tests ( 12.5%)
----------------------
Total: 8 tests
| Category | Description |
|---|---|
| Small | Tests marked with #[Small] attribute |
| Medium | Tests marked with #[Medium] attribute |
| Large | Tests marked with #[Large] attribute |
| None | Tests without any size attribute |
<?php
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\TestCase;
#[Small]
final class UserTest extends TestCase
{
public function testName(): void
{
// This test is counted as "Small"
}
}- Counted: Passed, Failed, and Errored tests
- Not counted: Skipped and Incomplete tests
-
Class-level attributes only: PHPUnit's size attributes (
#[Small],#[Medium],#[Large]) can only be applied at the class level, not on individual test methods. All test methods in a class inherit the class's size. -
DataProvider inheritance: Test cases generated by DataProviders inherit the size attribute from their test class.
-
No runtime detection: This extension reads PHPUnit's metadata attributes. It does not measure actual execution time or resource usage.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT License. See LICENSE for details.
Takuto Wada