codeception api测试
安装
php vendor/bin/codecept generate:suite api
配置
actor: ApiTester modules: enabled: - REST: url: http://serviceapp/api/v1/ depends: PhpBrowser part: Json
创建api测试文件
php vendor/bin/codecept generate:cest Api CreateUser
测试用例
class CreateUserCest { public function _before(ApiTester $I) { } // tests public function tryToTest(ApiTester $I) { $I->amHttpAuthenticated('service_user', '123456'); $I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded'); $I->haveHttpHeader('api_key', 'special-key'); $I->sendPost('/app/massage/api/index/index', [ 'name' => 'davert', 'email' => 'davert@codeception.com' ]); $I->seeResponseCodeIsSuccessful(); $I->seeResponseIsJson(); //$this->_before(); $I->seeResponseContains('{"success":true'); //$I->seeResponseIsJson(); } }