📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PHPUnit Testing Test Organization

Test Organization

4 min read
Organise tests into Unit/, Feature/, Integration/ and run subsets with --testsuite flag.

Organizing Tests

tests/
├── Unit/                    # Test single class/function
│   ├── Services/
│   │   ├── PaymentServiceTest.php
│   │   └── EmailServiceTest.php
│   ├── Models/
│   │   └── UserTest.php
│   └── Helpers/
│       └── StringHelperTest.php
│
├── Feature/                 # Test multiple layers together
│   ├── Auth/
│   │   ├── LoginTest.php
│   │   └── RegistrationTest.php
│   └── Api/
│       ├── UserApiTest.php
│       └── PostApiTest.php
│
└── Integration/             # Test with real DB/services
    └── DatabaseTest.php

// Run only one suite
./vendor/bin/phpunit --testsuite=Unit
./vendor/bin/phpunit --testsuite=Feature

// Run one file or test
./vendor/bin/phpunit tests/Unit/Services/PaymentServiceTest.php
./vendor/bin/phpunit --filter testProcessPaymentSuccess