您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit标注-testdox
发布时间:2021-10-07 22:29:44编辑:雪饮阅读()
testdox标注用于指定生成敏捷文档句子时使用的替换描述。测试类和测试方法都可以应用 @testdox 标注。
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @testdox 这是一个测试类
*/
final class MyTest extends TestCase
{
/**
* @testdox 这是一个测试方法
* @test
*/
public function wangZheRongYaoShiLaJi(): void
{
var_dump("王者荣耀是垃圾");
}
}
use PHPUnit\Framework\TestCase;
/**
* @testdox 这是一个测试类
*/
final class MyTest extends TestCase
{
/**
* @testdox 这是一个测试方法
* @test
*/
public function wangZheRongYaoShiLaJi(): void
{
var_dump("王者荣耀是垃圾");
}
}
运行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\phpunit -c C:\Users\Administrator\PhpstormProjects\untitled\organizing\phpunit.xml C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php --testdox
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
这是一个测试类
☢ 这是一个测试方法
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:14:
string(21) "王者荣耀是垃圾"
Time: 00:00.012, Memory: 6.00 MB
OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.
官方文档有标注:
在 PHPUnit 7.0 之前(由于标注解析中的一个 bug),使用 @testdox 标注也会激活 @test 标注的行为。
从我们上面这个执行效果,我的test标注确实是被执行了,但是我的版本可不是7.0之前,而是9.5.8:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\phpunit --version
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
原文参见:https://phpunit.readthedocs.io/zh_CN/latest/annotations.html#testdox
关键字词:phpunit,testdox