PHPUnit9.0 標注-@testdox

2022-03-24 11:01 更新
PHPUnit9.0 標注集合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? 聯(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)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號