Symfony 官方最佳实践里,有一个非常务实的建议:
先做 URL 级烟雾测试。
它很像政务巡查:
<?php
namespace App\Tests;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
final class ApplicationAvailabilityTest extends WebTestCase
{
#[DataProvider('urlProvider')]
public function testPageIsSuccessful(string $url): void
{
$client = self::createClient();
$client->request('GET', $url);
self::assertResponseIsSuccessful();
}
public static function urlProvider(): \Generator
{
yield ['/'];
yield ['/permits/new'];
}
}这类测试不复杂,但价值很高:
- 一眼知道主要页面是不是全挂了
- 对长期演进的老系统尤其重要
- 很适合做 CI 的第一道关
Symfony 的思路一直很成熟:
不是一开始就炫复杂测试花活
而是先把城区基础运转验明白