我正在尝试使用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
答案 0 :(得分:1)
您需要将可选参数传递给父构造函数。
如果你的测试课上有这个:
<?php
public function __construct() {
// Some constructor code.
}
改为:
<?php
public function __construct($name = null, array $data = [], $dataName = '') {
parent::__construct($name, $data, $dataName);
// Some constructor code.
}