測(cè)試方法可以接受任意參數(shù)。這些參數(shù)由一個(gè)或多個(gè)數(shù)據(jù)供給器方法(在使用返回?cái)?shù)組的數(shù)組的數(shù)據(jù)供給器中,是 ?provider()
? 方法)提供。用 ?@dataProvider
? 標(biāo)注來指定要使用的數(shù)據(jù)供給器方法。
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class DataTest extends TestCase
{
/**
* @dataProvider additionProvider
*/
public function testAdd(int $a, int $b, int $expected): void
{
$this->assertSame($expected, $a + $b);
}
public function additionProvider(): array
{
return [
[0, 0, 0],
[0, 1, 1],
[1, 0, 1],
[1, 1, 3]
];
}
}
更多建議: