您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit-标注-afterClass
发布时间:2021-10-06 15:29:55编辑:雪饮阅读()
@afterClass 标注用于指明此静态方法应该于测试类中的所有测试方法都运行完成之后调用,用于清理共享基境。
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
/**
* @afterClass
*/
public static function xunXing(): void
{
var_dump("运行结束".time());
}
public function testFixtures(): void
{
var_dump("运行开始:".time());
sleep(3);
$this->assertTrue(true);
}
}
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
/**
* @afterClass
*/
public static function xunXing(): void
{
var_dump("运行结束".time());
}
public function testFixtures(): void
{
var_dump("运行开始:".time());
sleep(3);
$this->assertTrue(true);
}
}
运行结果:
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
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)string(23) "运行开始:1633505264"
string(22) "运行结束1633505267"
Time: 00:03.019, Memory: 4.00 MB
OK (1 test, 1 assertion)
关键字词:phpunit,afterClass