我正在尝试使用创建一些编程测试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]
];
}
Run Code Online (Sandbox Code Playgroud)
我期望输出是:
There was 1 failure:
1) DataTest::testAdd with data set #3 (1, 1, 3)
Failed asserting that 2 is identical to 3.
Run Code Online (Sandbox Code Playgroud)
但它是:
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
Run Code Online (Sandbox Code Playgroud)
您需要将可选参数传递给父构造函数。
如果你的测试类中有这个:
<?php
public function __construct() {
// Some constructor code.
}
Run Code Online (Sandbox Code Playgroud)
将其更改为:
<?php
public function __construct($name = null, array $data = [], $dataName = '') {
parent::__construct($name, $data, $dataName);
// Some constructor code.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6308 次 |
| 最近记录: |