phpunit testdox与数据提供程序的友好输出

时间:2019-04-03 11:25:21

标签: phpunit

当我使用@dataProvider运行phpunit --testdox时,会得到如下输出:

MyTestClass
✔ My function data set ""
✔ My function data set ""
✔ My function data set ""

是否有一种方法可以使testdox显示每个数据集的友好描述?像这样:

MyTestClass
✔ My function data set "one"
✔ My function data set "two"
✔ My function data set "three"

示例代码:

class MyTestClassTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @dataProvider dataSets
     */
    public function testMyFunction(string $data)
    {
        $this->assertTrue(true);
    }

    public function dataSets()
    {
        return [
            ['one'],
            ['two'],
            ['three'],
        ];
    }
}

编辑

我正在使用phpunit版本7.3.2

1 个答案:

答案 0 :(得分:-1)

为日期集添加索引

MainApplication.java

这将输出:

class MyTestClassTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @dataProvider dataSets
     */
    public function testMyFunction(string $data)
    {
        $this->assertTrue(true);
    }

    public function dataSets()
    {
        return [
            'one' => ['one'],
            'two' => ['two'],
            'three' => ['three'],
        ];
    }
}

或者,您可以将My Test Class ✔ My function with one ✔ My function with two ✔ My function with three 添加到您的文档块中

@testdox

这将输出:

class MyTestClassTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @dataProvider dataSets
     * @testdox My custom testdox output with $data
     */
    public function testMyFunction(string $data)
    {
        $this->assertTrue(true);
    }

    public function dataSets()
    {
        return [
            ['one'],
            ['two'],
            ['three'],
        ];
    }
}