php - Test count is more than data count of data-provider in CodeCeption
问题描述
I have a Cest
in CodeCeption which uses a dataProvider
:
<?php
class MyCest
{
/**
* @param \Codeception\Example $example
* @dataProvider MyDataProvider
*/
public function MyTestCase(Codeception\Example $example)
{
echo "Name: ", $example['name'], ", Age: ", $example['age'];
}
public function MyDataProvider() {
$data = [
["name" => 'Alice', "age" => 20],
["name" => 'Tom', "age" => 35],
["name" => 'Bob', "age" => 60],
];
return $data;
}
}
As you see, it returns 3 data items, but when I run the test the log says we have 4 tests:
zeinab@zeinab:~/PhpstormProjects/api-testing$ php vendor/bin/codecept run tests/api/MyCest.php
Codeception PHP Testing Framework v2.5.1
Powered by PHPUnit 7.1.5 by Sebastian Bergmann and contributors.
Running with seed:
Api Tests (4) --------------------------------------------------------------------------------------
✔ MyCest: My test case | "Alice",20 (0.00s)ice, Age: 20
✔ MyCest: My test case | "Tom",35 (0.00s)m, Age: 35
✔ MyCest: My test case | "Bob",60 (0.00s)b, Age: 60
✔ MyCest: My data provider (0.00s)
----------------------------------------------------------------------------------------------------
Time: 63 ms, Memory: 10.00MB
OK (4 tests, 0 assertions)
I reviewed PHPUnit DataProvider documentation; its example implies that the number of tests are equal to the number of data items returned from dataProvider
method.
It seems call of the dataProvider
has been counted as a test case itself.
解决方案
类的所有公共方法Cest
都作为测试执行,
以避免将MyDataProvider
其保护或重命名_MyDataProvider
为https://codeception.com/docs/07-AdvancedUsage#DataProvider-Annotations中记录的
推荐阅读
- python - 信号和函数之间的 PyQt 程序连接不起作用
- javascript - 8皇后问题。这个 JavaScript 代码是如何工作的?
- python - 阅读熊猫专栏时出现奇怪的错误
- wpf - 如何将按钮样式添加到 wpf 中的窗口资源
- php - php mysql 加入两个表以加入一些列并联合一些列
- javascript - 使用 HTML5 和 JavaScript 暂停后,如何恢复播放来自网络源的音频?
- python - jinja2 模板中的 \n 会产生问题吗?
- javascript - 文件由 resteasy 返回,带有额外的字节
- java - 将所需变量传递给所有代码的最佳设计模式
- spring - Spring Cloud Data Flow REST API 组成的任务参数未传递给子任务