api測試類似屬於驗收測試(Acceptance Tests),這邊使用的是unit,根據需求而定
能讓普通人看得懂。
創建角色
class_name: ApiTester
bootstrap: false
modules:
enabled:
- Yii2:
part: fixtures
codecept build
生成角色
codecept build
創建一個api
codecept generate:test api /modules/buyer/index
生成的indexTest :
public function testInxex()
{
global $config;
$url = $config['api.host'].'/buyer/index/index';
$request = new Request();
$res = $request->curlRequest($url,'');
$data =json_decode($res,true);
$is_ok =false;
if($data['result'] == 1){
$is_ok = true;
}
$this->assertTrue($is_ok,'api獲取首頁數據失敗');
}
上面的Request 方法是自己寫的請求類,非codeception 自帶,請勿多想
執行:
codecept run unit --html
輸出html報告,打開:
如果獲取失敗了
都9012年了是該有界面了,贊!!!
名稱 | 地址 |
---|---|
中文文檔 | https://www.cloudxns.net/AccountSupport/index/u/950.html |
官方文檔(建議) | https://codeception.com/docs/03-AcceptanceTests |
博主自創專欄 | https://blog.csdn.net/qq_22823581/article/category/9380504 |
本篇參考 | https://www.jianshu.com/p/c9ee78e34fa5 |