我有一个Cest in CodeCeption,它使用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;
}
}正如您所看到的,它返回3个数据项,但是当我运行测试时,日志显示我们有4个测试:
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)我回顾了PHPUnit DataProvider文档;它的示例意味着测试的数量等于从dataProvider方法返回的数据项的数量。
看来dataProvider的调用本身已经被算作一个测试用例了。
发布于 2018-12-10 15:02:49
Cest类的所有公共方法都作为测试执行,
若要避免这种情况,请将MyDataProvider保护或将其重命名为_MyDataProvider
正如https://codeception.com/docs/07-AdvancedUsage#DataProvider-Annotations记录的那样
https://stackoverflow.com/questions/53682599
复制相似问题