PHPUnit9.0 标注-@testdox
2022-03-24 11:01 更新
PHPUnit9.0 标注集合
指定生成敏捷文档句子时使用的替换描述。
测试类和测试方法都可以应用 @testdox
标注。
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @testdox A bank account
*/
final class BankAccountTest extends TestCase
{
/**
* @testdox has an initial balance of zero
*/
public function balanceIsInitiallyZero(): void
{
$this->assertSame(0, $this->ba->getBalance());
}
}
在 PHPUnit 7.0 之前(由于标注解析中的一个 bug),使用 @testdox
标注也会激活 @test
标注的行为
如果将 @testdox
标注在方法级别和 @dataProvider
联用,可以在替换描述中将方法参数用作占位符。
/**
* @dataProvider additionProvider
* @testdox Adding $a to $b results in $expected
*/
public function testAdd($a, $b, $expected)
{
$this->assertSame($expected, $a + $b);
}
public function additionProvider()
{
return [
[0, 0, 0],
[0, 1, 1],
[1, 0, 1],
[1, 1, 3]
];
}
以上内容是否对您有帮助:
更多建议: