您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit使用testdox情况下多个测试方法的名字互相之间的差异只是一个或多个数字的后缀生成敏捷文档
发布时间:2021-09-17 22:50:01编辑:雪饮阅读()
上篇中了解了testdox的基本使用,那么假如一个测试类中有两个多多个方法仅仅只是一个或多个数字的后缀。像是如:testBalanceCannotBecomeNegative() 和 testBalanceCannotBecomeNegative2()。
那么这种情况则会在生成敏捷文档的过程中,对于像是这两种不同的方法名称会出现为去掉后面这些数字后缀的情况。
实例如:BankAccountTest.php:
<?php declare(strict_types=1);
//use PHPUnit\Framework\TestCase;
namespace TestNamespace;
use PHPUnit\Framework\TestCase;
class BankAccountTest extends TestCase
{
public function testBalanceIsInitiallyZero()
{
$this->assertTrue(true);
}
public function test_balance_is_initially_zero()
{
$this->assertTrue(false);
}
public function testBalanceCannotBecomeNegative()
{
$this->assertTrue(true);
}
public function testBalanceCannotBecomeNegative2()
{
$this->assertTrue(true);
}
}
//use PHPUnit\Framework\TestCase;
namespace TestNamespace;
use PHPUnit\Framework\TestCase;
class BankAccountTest extends TestCase
{
public function testBalanceIsInitiallyZero()
{
$this->assertTrue(true);
}
public function test_balance_is_initially_zero()
{
$this->assertTrue(false);
}
public function testBalanceCannotBecomeNegative()
{
$this->assertTrue(true);
}
public function testBalanceCannotBecomeNegative2()
{
$this->assertTrue(true);
}
}
运行效果如:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.3.4nts\php.exe D:\phpstudy_pro\Extensions\php\php7.3.4nts\phpunit-9.5.8.phar --testdox C:\Users\Administrator\PhpstormProjects\untitled\BankAccountTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
Bank Account (TestNamespace\BankAccount)
✔ Balance is initially zero
✘ Balance is initially zero
│
│ Failed asserting that false is true.
│
│ C:\Users\Administrator\PhpstormProjects\untitled\BankAccountTest.php:13
│
✔ Balance cannot become negative
✔ Balance cannot become negative
Time: 00:00.005, Memory: 20.00 MB
Summary of non-successful tests:
Bank Account (TestNamespace\BankAccount)
✘ Balance is initially zero
│
│ Failed asserting that false is true.
│
│ C:\Users\Administrator\PhpstormProjects\untitled\BankAccountTest.php:13
│
FAILURES!
Tests: 4, Assertions: 4, Failures: 1.
另外一点需要注意的就是这里可以看到每个测试有用对号的符号或者叉叉的符号表示该项测试是否成功,那么实际上这个在控制台中未必能显示出来
像是我win10中显示的都是这样的空格:
只是复制到word中就可以显示了,网页中好像也是可以显示的。
关键字词:phpunit,testdox,多个测试方法的名字互相之间的差异只是一个或多个数字的后缀