您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit标注-test
发布时间:2021-10-07 21:25:22编辑:雪饮阅读()
像是前面,我们对一个测试方法的方法名命名时候都是以”test”为前缀的,那么如果不想以”test”为前缀能做为测试方法正常运行吗?
答案是肯定的。
test标注就是来解决这个问题的。而且个人认为这样看起来更专业点。
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
/**
* @test
*/
public function wangZheRongYaoShiLaJi(): void
{
var_dump("王者荣耀是垃圾");
}
}
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
/**
* @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
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
R 1 / 1 (100%)C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:10:
string(21) "王者荣耀是垃圾"
Time: 00:00.013, Memory: 6.00 MB
There was 1 risky test:
1) MyTest::wangZheRongYaoShiLaJi
This test did not perform any assertions
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:8
OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.
关键字词:phpunit,test