【发布时间】:2021-03-17 23:27:17
【问题描述】:
我正在尝试使用phpUnit 创建一些编程测试。
我需要使用数据提供程序,但每次尝试时都会引发错误。
我什至在使用phpUnit 文档中给出的示例。
/**
* @dataProvider additionWithNonNegativeNumbersProvider
*/
public function testAdd($a, $b, $expected)
{
$this->assertSame($expected, $a + $b);
}
public function additionWithNonNegativeNumbersProvider()
{
return [
[0, 1, 1],
[1, 0, 1],
[1, 1, 3]
];
}
我希望输出是:
There was 1 failure:
1) DataTest::testAdd with data set #3 (1, 1, 3)
Failed asserting that 2 is identical to 3.
但它是:
ArgumentCountError : Too few arguments to function controllerTests::testAdd(), 0 passed in phar://C:/xampp/htdocs/2019-1-qa-grupo1/myss/Tests/phpunit-8.1.2.phar/phpunit/Framework/TestCase.php on line 1172 and exactly 3 expected
C:\xampp\htdocs\2019-1-qa-grupo1\myss\Tests\controllerTests.php:55
【问题讨论】:
-
我无法复制它。您是否在测试类中定义了构造函数?如果您不调用父构造函数,这可能会破坏事情:stackoverflow.com/questions/10175414/…
-
我已经定义了我的构造函数。但它调用父构造函数。我刚刚意识到我的 IDE 显示消息“类父级存在多个定义”
-
就像我链接到的那个问题的第二个答案中显示的那样?致电
parent::__construct()将不起作用。 (只是确保) -
谢谢,我没有看到第二个答案。