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

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

測試方法可以接受任意參數(shù)。這些參數(shù)由一個或多個數(shù)據(jù)供給器方法(在使用返回數(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]
        ];
    }
}


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

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號