我正在尝试使用 PHPUnit 12 dataProviders 向要测试的函数提供数据,但无法使其正常工作。
这是我的单元测试(位于tests/TestTest.php
):
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class TestTest extends TestCase
{
public static function dataProvider(): array
{
return [['a'], ['b']];
}
#[DataProvider("dataProvider")]
public function testTest($var): void
{
$this->assertTrue(true);
}
}
当我跑步时./vendor/bin/phpunit tests
我得到了这个:
PHPUnit 12.0.0 by Sebastian Bergmann and contributors.
Runtime: PHP 8.3.14
E 1 / 1 (100%)
Time: 00:00.019, Memory: 8.00 MB
There was 1 error:
1) TestTest::testTest
ArgumentCountError: Too few arguments to function TestTest::testTest(), 0 passed in C:\path\to\vendor\phpunit\phpunit\src\Framework\TestCase.php on line 1104 and exactly 1 expected
C:\path\to\tests\TestTest.php:12
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
有什么想法吗?