您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit标注-runTestsInSeparateProcesses
发布时间:2021-10-07 20:00:46编辑:雪饮阅读()
@runTestsInSeparateProcesses
指明单个测试类内的所有测试要各自运行在独立的 PHP 进程中。
这同上篇中的runInSeparateProcess标注类似,只是runInSeparateProcess标注仅仅指定某个测试方法而runTestsInSeparateProcesses标注则是指定某个测试类中所有测试方法。
一个具体的实例:
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @runTestsInSeparateProcesses
*/
final class MyTest extends TestCase
{
public function testInSeparateProcess(): void
{
var_dump("\r\n".posix_getpid()."\r\n");
}
public function testTwo(): void
{
var_dump("\r\n".posix_getpid()."\r\n");
}
}
use PHPUnit\Framework\TestCase;
/**
* @runTestsInSeparateProcesses
*/
final class MyTest extends TestCase
{
public function testInSeparateProcess(): void
{
var_dump("\r\n".posix_getpid()."\r\n");
}
public function testTwo(): void
{
var_dump("\r\n".posix_getpid()."\r\n");
}
}
同样的这里的posix_getpid方法也是只能在linux中运行。
运行结果如:
[root@localhost ~]# /usr/local/php734/bin/php /usr/local/phpunit-9.5.8.phar /usr/local/organizing/tests/MyTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
Rstring(9) "
14456
"
R 2 / 2 (100%)string(9) "
14463
"
Time: 00:00.181, Memory: 18.00 MB
There were 2 risky tests:
1) MyTest::testInSeparateProcess
This test did not perform any assertions
/usr/local/organizing/tests/MyTest.php:8
2) MyTest::testTwo
This test did not perform any assertions
/usr/local/organizing/tests/MyTest.php:12
OK, but incomplete, skipped, or risky tests!
Tests: 2, Assertions: 0, Risky: 2.
关键字词:phpunit,runTestsInSeparateProcesses