您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit标注-ticket
发布时间:2021-10-08 19:58:14编辑:雪饮阅读()
ticket标注其实和group标注是差不多的。
对于如下实例:
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
/**
* @ticket group1
* @testWith ["test", 4]
* ["longer-string", 13]
*/
public function testStringLength(string $input, int $expectedLength): void
{
$this->assertSame($expectedLength, strlen($input));
}
//以 JSON 格式表示的对象会转换为关联数组。
/**
* @ticket group1
* @testWith [{"day": "monday", "conditions": "sunny"}, ["day", "conditions"]]
*/
public function testArrayKeys(array $array, array $keys): void
{
var_dump(array_keys($array));
var_dump($keys);
$this->assertSame($keys, array_keys($array));
}
/**
* @ticket group2
*/
public function testQu(){
$this->assertTrue(true);
}
}
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
/**
* @ticket group1
* @testWith ["test", 4]
* ["longer-string", 13]
*/
public function testStringLength(string $input, int $expectedLength): void
{
$this->assertSame($expectedLength, strlen($input));
}
//以 JSON 格式表示的对象会转换为关联数组。
/**
* @ticket group1
* @testWith [{"day": "monday", "conditions": "sunny"}, ["day", "conditions"]]
*/
public function testArrayKeys(array $array, array $keys): void
{
var_dump(array_keys($array));
var_dump($keys);
$this->assertSame($keys, array_keys($array));
}
/**
* @ticket group2
*/
public function testQu(){
$this->assertTrue(true);
}
}
我们可以用--group将ticket名称传入
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 --group group2
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 00:02.255, Memory: 6.00 MB
OK (1 test, 1 assertion)
像这类就仅仅查看ticket为group2的。
那么同样的,如果不用—group则就是全部test方法都执行:
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.
...C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:21:
array(2) {
[0] =>
string(3) "day"
[1] =>
string(10) "conditions"
}
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\MyTest.php:22:
array(2) {
[0] =>
string(3) "day"
[1] =>
string(10) "conditions"
}
. 4 / 4 (100%)
Time: 00:00.009, Memory: 6.00 MB
OK (4 tests, 4 assertions)
关键字词:phpunit,ticket