php批量测试api接口汇总结果代码
代码语言:php
所属分类:其他
代码描述:php批量测试api接口汇总结果代码
代码标签: php 批量 测试 api 接口 汇总 结果 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<?php // run_tests.php - Automated API Test Runner // Execute via CLI: php run_tests.php > test_report.html // --- Configuration --- $api_base_url = "http://127.0.0.1"; // 您的本地服务器地址 $cookie_file = tempnam(sys_get_temp_dir(), 'api_test_cookie'); $context = []; // 用于在测试之间传递数据 (e.g., new order_id) // --- Test Suite Definition --- // 定义一个有逻辑顺序的测试套件 $test_suite = [ 'User Flow' => [ [ 'name' => 'Register New User', 'method' => 'POST', 'url' => '/api/auth/register', 'body' => '{"username": "autotestuser'.time().'", "email": "autotest'.time().'@example.com", "password": "password"}', 'expected_status' => 200, ], [ 'name' => 'Login as User', 'method' => 'POST', 'url' => '/api/auth/login', 'body' => '{"email": "user@example.com", "password": "password"}', 'expected_status' => 200, 'capture' => ['user.id' => 'user.id'] ], [ 'name' => 'Create a new Address', 'method' => 'POST', 'url' => '/api/user/addresses', 'body' => '{"contact_name":"Auto Test","contact_phone":"13812345678","province":"北京","city":"北京市","district":"海淀区","detail":"中关村","is_default":true}', 'expected_status' => 200, 'capture' => ['address.id' => 'id'] ], [ 'name' => 'Create an Order', 'method' => 'POST', 'url' => '/api/user/orders', 'body' => '{"service_id":1,"address_id":"{{address.id}}","appointment_time":"2025-01-01 10:00:00","technician_id":1}', 'expected_status' => 200, 'capture' => ['order.id' => 'order_id'] ], [ 'name' => 'Get Order Details', 'method' => 'GET', 'url' => '/api/user/orders/{{order.id}}', 'expected_status' => 200, 'validations' => ['assert_key_exists' => 'order_sn'] ], [ 'name' => 'Logout User', 'method' => 'POST', 'url' => '/api/auth/logout', 'expected_status' => 200, ], ], 'Technician Flow' => [ [ 'name' => 'Login as Technician', 'method' => 'POST', 'url' => '/api/auth/technician/login', 'body' => '{"email": "tech01@example.com", "password": "password"}'.........完整代码请登录后点击上方下载按钮下载查看
网友评论0