20], ["name" => 'Tom', "ag-6ren">
gpt4 book ai didi

php - 测试计数大于 CodeCeption 中数据提供者的数据计数

转载 作者:行者123 更新时间:2023-12-05 06:29:17 25 4
gpt4 key购买 nike

我在 CodeCeption 中有一个 Cest,它使用 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 documentation ;它的示例暗示测试的数量等于从 dataProvider 方法返回的数据项的数量。

看来 dataProvider 的调用本身已被计为测试用例。

最佳答案

Cest 类的所有公共(public)方法都作为测试执行,
避免使 MyDataProvider 受到保护或将其重命名为 _MyDataProvider
如记录在 https://codeception.com/docs/07-AdvancedUsage#DataProvider-Annotations

关于php - 测试计数大于 CodeCeption 中数据提供者的数据计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53682599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com