phpunit testdox友好输出,带有数据提供程序
当我使用@dataProvider运行phpunit testdox友好输出,带有数据提供程序,phpunit,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 func
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为日期集添加索引
class MyTestClassTest扩展\PHPUnit\Framework\TestCase
{
/**
*@dataProvider数据集
*/
公共函数testMyFunction(字符串$data)
{
$this->assertTrue(true);
}
公共函数数据集()
{
返回[
“一”=>[“一”],
“两个”=>[“两个”],
“三”=>[“三”],
];
}
}
这将输出:
My Test Class
✔ My function with one
✔ My function with two
✔ My function with three
My Test Class
✔ My custom testdox output with one
✔ My custom testdox output with two
✔ My custom testdox output with three
或者,您可以将@testdox
添加到docblock
class MyTestClassTest扩展\PHPUnit\Framework\TestCase
{
/**
*@dataProvider数据集
*@testdox我的自定义testdox输出和$data
*/
公共函数testMyFunction(字符串$data)
{
$this->assertTrue(true);
}
公共函数数据集()
{
返回[
[‘一’,
['two'],
[‘三’],
];
}
}
这将输出:
My Test Class
✔ My function with one
✔ My function with two
✔ My function with three
My Test Class
✔ My custom testdox output with one
✔ My custom testdox output with two
✔ My custom testdox output with three
您使用哪个版本的PHPUnit?在最近的版本中,已经做了很多工作来改进TestDox输出。@SebastianBergmann phpunit 7.3.2版(本应提出这个问题)为什么您一直停留在phpunit 7.3上?请更新至PHPUnit 7.5的最新版本。它与phpunit7.3向后兼容,应该已经更好了。帮你自己一个忙,更新到最新的phpunit8。它有更好的TestDox功能,特别是在数据提供程序方面。@SebastianBergmann没有理由只是有一段时间没有运行composer update
!我一定会检查版本8。看起来我需要对我的测试代码做一些修改。@SebastianBergmann版本8更好,因为它显示的是set\1
等,而不仅仅是”
。如果有一个选项可以显示数据集值,比如--debug
标志是如何显示的,那就太好了。我会更新您的答案,添加更多关于需要应用此更改的位置和原因的上下文。