PHPUnit:运行使用特定属性的测试

问题描述 投票:0回答:1

我在一些测试中使用了

RequiresFunction
属性。我想将参数传递给
phpunit
,它将使用该属性和所需函数的名称(如果可能)运行测试。

测试看起来像这样:

use PHPUnit\Framework\Attributes\RequiresFunction;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

class MyCustomFunctionTest extends TestCase
{
    #[Test]
    #[RequiresFunction('some_function_name')
    public function some_function_name_destroys_the_planet(): void
    {
        $this->assertTrue(true);
    }
}
php laravel attributes phpunit
1个回答
0
投票

如果您想运行需要特定函数(如 some_function_name)的测试,您可以使用 PHPUnit 的

--filter
选项。但是,
--filter
选项适用于测试方法或类的名称,而不是直接适用于 RequiresFunction 等属性。

此命令将运行名称包含

some_function_name
的所有测试。

phpunit --filter '/some_function_name/'
© www.soinside.com 2019 - 2024. All rights reserved.