【codeception 三】 api 测试

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章