PHPUnit9.0 標(biāo)注-@testdox

2022-03-24 11:01 更新
PHPUnit9.0 標(biāo)注集合PHPUnit9.0 標(biāo)注集合

指定生成敏捷文檔句子時(shí)使用的替換描述。

測(cè)試類和測(cè)試方法都可以應(yīng)用 ?@testdox? 標(biāo)注。

<?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 之前(由于標(biāo)注解析中的一個(gè) bug),使用 ?@testdox? 標(biāo)注也會(huì)激活 ?@test? 標(biāo)注的行為

如果將 ?@testdox? 標(biāo)注在方法級(jí)別和 ?@dataProvider? 聯(lián)用,可以在替換描述中將方法參數(shù)用作占位符。

/**
 * @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]
    ];
}


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)