[英]How do you handle dependency in api testing?
我有大型 api,我想为每个端点编写 api 测试。 我应该如何处理依赖于其他端点 id 的测试端点?
在我们的应用程序中,我们必须先创建客户端,然后是分支,然后是产品,然后为该分支订购。 所以如果我正在测试
POST /clients
POST /branches
POST /products
POST /orders
我应该在每个端点的每次测试之前编写创建客户端吗?
您可以为此使用 cURL PHP
关注: https ://www.php.net/manual/pt_BR/book.curl.php
或者您可以运行以下代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com"); // API url
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // for get retutn requsert
curl_setopt($ch, CURLOPT_POST, 1); // for use post requsert
curl_setopt($ch, CURLOPT_POSTFIELDS, ['key'=>'value']); // for post data
$res = curl_exec($ch); // for close requset
if (curl_error($ch)) {
var_dump(curl_error($ch)); // for print error
} else {
print_r($res); // for print result
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.