文章目录
- [10 接口功能测试实战 - 从理论到实践](#10 接口功能测试实战 - 从理论到实践)
-
- [10.1 测试对象介绍](#10.1 测试对象介绍)
- [10.2 测试流程](#10.2 测试流程)
- [10.3 模块一:用户模块测试](#10.3 模块一:用户模块测试)
- [10.4 模块二:商品模块测试](#10.4 模块二:商品模块测试)
- [10.5 模块三:购物车模块测试](#10.5 模块三:购物车模块测试)
- [10.6 模块四:订单模块测试](#10.6 模块四:订单模块测试)
- [10.7 测试执行记录](#10.7 测试执行记录)
- [10.8 缺陷报告示例](#10.8 缺陷报告示例)
- [10.9 本章小结](#10.9 本章小结)
-
- 实战要点
- [课后练习 📝](#课后练习 📝)
- [10.10 下章预告](#10.10 下章预告)
10 接口功能测试实战 - 从理论到实践
🎯 本章目标:通过一个完整的电商系统接口测试案例,掌握接口测试的完整流程。
10.1 测试对象介绍
电商系统接口
我们将测试一个简化的电商系统,包含以下模块:
#mermaid-svg-54Tov2VJ2eAG8UCb{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-54Tov2VJ2eAG8UCb .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-54Tov2VJ2eAG8UCb .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-54Tov2VJ2eAG8UCb .error-icon{fill:#552222;}#mermaid-svg-54Tov2VJ2eAG8UCb .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-54Tov2VJ2eAG8UCb .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-54Tov2VJ2eAG8UCb .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-54Tov2VJ2eAG8UCb .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-54Tov2VJ2eAG8UCb .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-54Tov2VJ2eAG8UCb .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-54Tov2VJ2eAG8UCb .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-54Tov2VJ2eAG8UCb .marker{fill:#333333;stroke:#333333;}#mermaid-svg-54Tov2VJ2eAG8UCb .marker.cross{stroke:#333333;}#mermaid-svg-54Tov2VJ2eAG8UCb svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-54Tov2VJ2eAG8UCb p{margin:0;}#mermaid-svg-54Tov2VJ2eAG8UCb .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-54Tov2VJ2eAG8UCb .cluster-label text{fill:#333;}#mermaid-svg-54Tov2VJ2eAG8UCb .cluster-label span{color:#333;}#mermaid-svg-54Tov2VJ2eAG8UCb .cluster-label span p{background-color:transparent;}#mermaid-svg-54Tov2VJ2eAG8UCb .label text,#mermaid-svg-54Tov2VJ2eAG8UCb span{fill:#333;color:#333;}#mermaid-svg-54Tov2VJ2eAG8UCb .node rect,#mermaid-svg-54Tov2VJ2eAG8UCb .node circle,#mermaid-svg-54Tov2VJ2eAG8UCb .node ellipse,#mermaid-svg-54Tov2VJ2eAG8UCb .node polygon,#mermaid-svg-54Tov2VJ2eAG8UCb .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-54Tov2VJ2eAG8UCb .rough-node .label text,#mermaid-svg-54Tov2VJ2eAG8UCb .node .label text,#mermaid-svg-54Tov2VJ2eAG8UCb .image-shape .label,#mermaid-svg-54Tov2VJ2eAG8UCb .icon-shape .label{text-anchor:middle;}#mermaid-svg-54Tov2VJ2eAG8UCb .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-54Tov2VJ2eAG8UCb .rough-node .label,#mermaid-svg-54Tov2VJ2eAG8UCb .node .label,#mermaid-svg-54Tov2VJ2eAG8UCb .image-shape .label,#mermaid-svg-54Tov2VJ2eAG8UCb .icon-shape .label{text-align:center;}#mermaid-svg-54Tov2VJ2eAG8UCb .node.clickable{cursor:pointer;}#mermaid-svg-54Tov2VJ2eAG8UCb .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-54Tov2VJ2eAG8UCb .arrowheadPath{fill:#333333;}#mermaid-svg-54Tov2VJ2eAG8UCb .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-54Tov2VJ2eAG8UCb .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-54Tov2VJ2eAG8UCb .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-54Tov2VJ2eAG8UCb .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-54Tov2VJ2eAG8UCb .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-54Tov2VJ2eAG8UCb .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-54Tov2VJ2eAG8UCb .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-54Tov2VJ2eAG8UCb .cluster text{fill:#333;}#mermaid-svg-54Tov2VJ2eAG8UCb .cluster span{color:#333;}#mermaid-svg-54Tov2VJ2eAG8UCb div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-54Tov2VJ2eAG8UCb .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-54Tov2VJ2eAG8UCb rect.text{fill:none;stroke-width:0;}#mermaid-svg-54Tov2VJ2eAG8UCb .icon-shape,#mermaid-svg-54Tov2VJ2eAG8UCb .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-54Tov2VJ2eAG8UCb .icon-shape p,#mermaid-svg-54Tov2VJ2eAG8UCb .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-54Tov2VJ2eAG8UCb .icon-shape .label rect,#mermaid-svg-54Tov2VJ2eAG8UCb .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-54Tov2VJ2eAG8UCb .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-54Tov2VJ2eAG8UCb .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-54Tov2VJ2eAG8UCb :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 电商系统
用户模块
商品模块
购物车模块
订单模块
支付模块
注册/登录
商品列表/详情
加购/修改数量
创建/查询订单
支付/退款
测试环境
Base URL: https://api-shop.example.com
版本: v1
数据格式: JSON
认证方式: Bearer Token
10.2 测试流程
#mermaid-svg-rua7aFB92GbN9zjS{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-rua7aFB92GbN9zjS .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-rua7aFB92GbN9zjS .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-rua7aFB92GbN9zjS .error-icon{fill:#552222;}#mermaid-svg-rua7aFB92GbN9zjS .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-rua7aFB92GbN9zjS .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-rua7aFB92GbN9zjS .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-rua7aFB92GbN9zjS .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-rua7aFB92GbN9zjS .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-rua7aFB92GbN9zjS .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-rua7aFB92GbN9zjS .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-rua7aFB92GbN9zjS .marker{fill:#333333;stroke:#333333;}#mermaid-svg-rua7aFB92GbN9zjS .marker.cross{stroke:#333333;}#mermaid-svg-rua7aFB92GbN9zjS svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-rua7aFB92GbN9zjS p{margin:0;}#mermaid-svg-rua7aFB92GbN9zjS .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-rua7aFB92GbN9zjS .cluster-label text{fill:#333;}#mermaid-svg-rua7aFB92GbN9zjS .cluster-label span{color:#333;}#mermaid-svg-rua7aFB92GbN9zjS .cluster-label span p{background-color:transparent;}#mermaid-svg-rua7aFB92GbN9zjS .label text,#mermaid-svg-rua7aFB92GbN9zjS span{fill:#333;color:#333;}#mermaid-svg-rua7aFB92GbN9zjS .node rect,#mermaid-svg-rua7aFB92GbN9zjS .node circle,#mermaid-svg-rua7aFB92GbN9zjS .node ellipse,#mermaid-svg-rua7aFB92GbN9zjS .node polygon,#mermaid-svg-rua7aFB92GbN9zjS .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-rua7aFB92GbN9zjS .rough-node .label text,#mermaid-svg-rua7aFB92GbN9zjS .node .label text,#mermaid-svg-rua7aFB92GbN9zjS .image-shape .label,#mermaid-svg-rua7aFB92GbN9zjS .icon-shape .label{text-anchor:middle;}#mermaid-svg-rua7aFB92GbN9zjS .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-rua7aFB92GbN9zjS .rough-node .label,#mermaid-svg-rua7aFB92GbN9zjS .node .label,#mermaid-svg-rua7aFB92GbN9zjS .image-shape .label,#mermaid-svg-rua7aFB92GbN9zjS .icon-shape .label{text-align:center;}#mermaid-svg-rua7aFB92GbN9zjS .node.clickable{cursor:pointer;}#mermaid-svg-rua7aFB92GbN9zjS .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-rua7aFB92GbN9zjS .arrowheadPath{fill:#333333;}#mermaid-svg-rua7aFB92GbN9zjS .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-rua7aFB92GbN9zjS .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-rua7aFB92GbN9zjS .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-rua7aFB92GbN9zjS .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-rua7aFB92GbN9zjS .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-rua7aFB92GbN9zjS .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-rua7aFB92GbN9zjS .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-rua7aFB92GbN9zjS .cluster text{fill:#333;}#mermaid-svg-rua7aFB92GbN9zjS .cluster span{color:#333;}#mermaid-svg-rua7aFB92GbN9zjS div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-rua7aFB92GbN9zjS .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-rua7aFB92GbN9zjS rect.text{fill:none;stroke-width:0;}#mermaid-svg-rua7aFB92GbN9zjS .icon-shape,#mermaid-svg-rua7aFB92GbN9zjS .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-rua7aFB92GbN9zjS .icon-shape p,#mermaid-svg-rua7aFB92GbN9zjS .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-rua7aFB92GbN9zjS .icon-shape .label rect,#mermaid-svg-rua7aFB92GbN9zjS .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-rua7aFB92GbN9zjS .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-rua7aFB92GbN9zjS .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-rua7aFB92GbN9zjS :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 需求分析
接口文档分析
用例设计
环境准备
执行测试
缺陷提交
回归测试
测试报告
10.3 模块一:用户模块测试
接口列表
| 接口 | 方法 | 路径 | 说明 |
|---|---|---|---|
| 注册 | POST | /api/v1/users | 创建新用户 |
| 登录 | POST | /api/v1/auth/login | 用户登录 |
| 获取信息 | GET | /api/v1/users/me | 获取当前用户 |
注册接口测试
正常场景:
bash
curl -X POST https://api-shop.example.com/api/v1/users \
-H "Content-Type: application/json" \
-d '{
"username": "testuser001",
"email": "test001@example.com",
"password": "123456"
}'
预期响应:
json
{
"code": 0,
"message": "注册成功",
"data": {
"id": 10001,
"username": "testuser001",
"email": "test001@example.com"
}
}
异常场景测试:
| 场景 | 请求 | 预期状态码 | 预期响应 |
|---|---|---|---|
| 用户名已存在 | 相同username | 409 | 用户名已存在 |
| 邮箱已存在 | 相同email | 409 | 邮箱已存在 |
| 用户名过短 | "ab" | 400 | 用户名3-20位 |
| 密码过短 | "123" | 400 | 密码6-20位 |
| 邮箱格式错误 | "not-email" | 400 | 邮箱格式错误 |
登录接口测试
正常登录:
bash
curl -X POST https://api-shop.example.com/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "testuser001",
"password": "123456"
}'
预期响应:
json
{
"code": 0,
"message": "登录成功",
"data": {
"token": "eyJhbGciOiJIUzI1NiIs...",
"expires": 3600
}
}
10.4 模块二:商品模块测试
接口列表
| 接口 | 方法 | 路径 | 说明 |
|---|---|---|---|
| 商品列表 | GET | /api/v1/products | 分页获取商品 |
| 商品详情 | GET | /api/v1/products/{id} | 获取单个商品 |
商品列表测试
正常请求:
bash
curl "https://api-shop.example.com/api/v1/products?page=1&size=10"
带筛选条件:
bash
# 按分类筛选
curl "https://api-shop.example.com/api/v1/products?category=phone&page=1&size=10"
# 按价格排序
curl "https://api-shop.example.com/api/v1/products?sort=price&order=asc"
边界值测试:
| 场景 | 参数 | 预期 |
|---|---|---|
| page=0 | page=0 | 返回第一页或错误 |
| page=最大值 | page=999999 | 返回空列表 |
| size=最大值 | size=100 | 返回100条 |
| size=超过最大值 | size=101 | 限制为100或错误 |
10.5 模块三:购物车模块测试
接口列表
| 接口 | 方法 | 路径 | 说明 |
|---|---|---|---|
| 加入购物车 | POST | /api/v1/cart/items | 添加商品 |
| 获取购物车 | GET | /api/v1/cart | 获取购物车内容 |
| 修改数量 | PUT | /api/v1/cart/items/{id} | 修改商品数量 |
| 删除商品 | DELETE | /api/v1/cart/items/{id} | 删除商品 |
加入购物车测试
需要认证:
bash
curl -X POST https://api-shop.example.com/api/v1/cart/items \
-H "Content-Type: application/json" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..." \
-d '{
"productId": 1001,
"quantity": 2
}'
场景测试:
| 场景 | 参数 | 预期 |
|---|---|---|
| 正常加购 | productId=1001, quantity=2 | 成功,购物车显示 |
| 加购不存在商品 | productId=99999 | 404,商品不存在 |
| 数量为0 | quantity=0 | 400,数量必须大于0 |
| 超过库存 | quantity=9999 | 400,库存不足 |
| 未登录 | 无Token | 401,未认证 |
10.6 模块四:订单模块测试
下单流程
DB API User DB API User #mermaid-svg-gGc878EV4xRqVvuF{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-gGc878EV4xRqVvuF .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-gGc878EV4xRqVvuF .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-gGc878EV4xRqVvuF .error-icon{fill:#552222;}#mermaid-svg-gGc878EV4xRqVvuF .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-gGc878EV4xRqVvuF .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-gGc878EV4xRqVvuF .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-gGc878EV4xRqVvuF .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-gGc878EV4xRqVvuF .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-gGc878EV4xRqVvuF .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-gGc878EV4xRqVvuF .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-gGc878EV4xRqVvuF .marker{fill:#333333;stroke:#333333;}#mermaid-svg-gGc878EV4xRqVvuF .marker.cross{stroke:#333333;}#mermaid-svg-gGc878EV4xRqVvuF svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-gGc878EV4xRqVvuF p{margin:0;}#mermaid-svg-gGc878EV4xRqVvuF .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-gGc878EV4xRqVvuF text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-gGc878EV4xRqVvuF .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-gGc878EV4xRqVvuF .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-gGc878EV4xRqVvuF .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-gGc878EV4xRqVvuF .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-gGc878EV4xRqVvuF #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-gGc878EV4xRqVvuF .sequenceNumber{fill:white;}#mermaid-svg-gGc878EV4xRqVvuF #sequencenumber{fill:#333;}#mermaid-svg-gGc878EV4xRqVvuF #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-gGc878EV4xRqVvuF .messageText{fill:#333;stroke:none;}#mermaid-svg-gGc878EV4xRqVvuF .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-gGc878EV4xRqVvuF .labelText,#mermaid-svg-gGc878EV4xRqVvuF .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-gGc878EV4xRqVvuF .loopText,#mermaid-svg-gGc878EV4xRqVvuF .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-gGc878EV4xRqVvuF .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-gGc878EV4xRqVvuF .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-gGc878EV4xRqVvuF .noteText,#mermaid-svg-gGc878EV4xRqVvuF .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-gGc878EV4xRqVvuF .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-gGc878EV4xRqVvuF .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-gGc878EV4xRqVvuF .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-gGc878EV4xRqVvuF .actorPopupMenu{position:absolute;}#mermaid-svg-gGc878EV4xRqVvuF .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-gGc878EV4xRqVvuF .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-gGc878EV4xRqVvuF .actor-man circle,#mermaid-svg-gGc878EV4xRqVvuF line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-gGc878EV4xRqVvuF :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} POST /orders (购物车商品) 检查库存 库存充足 创建订单 扣减库存 订单创建成功
创建订单测试
正常下单:
bash
curl -X POST https://api-shop.example.com/api/v1/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer token..." \
-d '{
"addressId": 1,
"remark": "请尽快发货"
}'
幂等性测试:
bash
# 快速连续提交两次相同请求
# 预期:只创建一个订单
10.7 测试执行记录
测试记录表
| 用例编号 | 模块 | 标题 | 状态 | 备注 |
|---|---|---|---|---|
| USER-001 | 用户 | 正常注册 | Pass | - |
| USER-002 | 用户 | 重复注册 | Pass | - |
| USER-003 | 用户 | 用户名过短 | Pass | - |
| PROD-001 | 商品 | 获取商品列表 | Pass | - |
| PROD-002 | 商品 | 分页边界值 | Fail | page=0返回500 |
| CART-001 | 购物车 | 正常加购 | Pass | - |
| CART-002 | 购物车 | 未登录加购 | Pass | 返回401 |
| ORDER-001 | 订单 | 正常下单 | Pass | - |
| ORDER-002 | 订单 | 库存不足 | Pass | 返回400 |
10.8 缺陷报告示例
缺陷报告
缺陷编号: BUG-001
缺陷标题: 分页参数page=0时返回500错误
严重程度: 高
优先级: 高
复现步骤:
1. 调用 GET /api/v1/products?page=0&size=10
2. 观察响应
实际结果:
状态码: 500
响应: {"code":500,"message":"Internal Server Error"}
预期结果:
状态码: 400
响应: {"code":400,"message":"page参数必须大于0"}
或返回第一页数据
10.9 本章小结
实战要点
#mermaid-svg-fwYux79g7F3scIRJ{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-fwYux79g7F3scIRJ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-fwYux79g7F3scIRJ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-fwYux79g7F3scIRJ .error-icon{fill:#552222;}#mermaid-svg-fwYux79g7F3scIRJ .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-fwYux79g7F3scIRJ .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-fwYux79g7F3scIRJ .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-fwYux79g7F3scIRJ .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-fwYux79g7F3scIRJ .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-fwYux79g7F3scIRJ .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-fwYux79g7F3scIRJ .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-fwYux79g7F3scIRJ .marker{fill:#333333;stroke:#333333;}#mermaid-svg-fwYux79g7F3scIRJ .marker.cross{stroke:#333333;}#mermaid-svg-fwYux79g7F3scIRJ svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-fwYux79g7F3scIRJ p{margin:0;}#mermaid-svg-fwYux79g7F3scIRJ .edge{stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .section--1 rect,#mermaid-svg-fwYux79g7F3scIRJ .section--1 path,#mermaid-svg-fwYux79g7F3scIRJ .section--1 circle,#mermaid-svg-fwYux79g7F3scIRJ .section--1 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section--1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section--1 text{fill:#ffffff;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon--1{font-size:40px;color:#ffffff;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge--1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth--1{stroke-width:17;}#mermaid-svg-fwYux79g7F3scIRJ .section--1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-0 rect,#mermaid-svg-fwYux79g7F3scIRJ .section-0 path,#mermaid-svg-fwYux79g7F3scIRJ .section-0 circle,#mermaid-svg-fwYux79g7F3scIRJ .section-0 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-fwYux79g7F3scIRJ .section-0 text{fill:black;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon-0{font-size:40px;color:black;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth-0{stroke-width:14;}#mermaid-svg-fwYux79g7F3scIRJ .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-1 rect,#mermaid-svg-fwYux79g7F3scIRJ .section-1 path,#mermaid-svg-fwYux79g7F3scIRJ .section-1 circle,#mermaid-svg-fwYux79g7F3scIRJ .section-1 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section-1 text{fill:black;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon-1{font-size:40px;color:black;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth-1{stroke-width:11;}#mermaid-svg-fwYux79g7F3scIRJ .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-2 rect,#mermaid-svg-fwYux79g7F3scIRJ .section-2 path,#mermaid-svg-fwYux79g7F3scIRJ .section-2 circle,#mermaid-svg-fwYux79g7F3scIRJ .section-2 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section-2 text{fill:#ffffff;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth-2{stroke-width:8;}#mermaid-svg-fwYux79g7F3scIRJ .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-3 rect,#mermaid-svg-fwYux79g7F3scIRJ .section-3 path,#mermaid-svg-fwYux79g7F3scIRJ .section-3 circle,#mermaid-svg-fwYux79g7F3scIRJ .section-3 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section-3 text{fill:black;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon-3{font-size:40px;color:black;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth-3{stroke-width:5;}#mermaid-svg-fwYux79g7F3scIRJ .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-4 rect,#mermaid-svg-fwYux79g7F3scIRJ .section-4 path,#mermaid-svg-fwYux79g7F3scIRJ .section-4 circle,#mermaid-svg-fwYux79g7F3scIRJ .section-4 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section-4 text{fill:black;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon-4{font-size:40px;color:black;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth-4{stroke-width:2;}#mermaid-svg-fwYux79g7F3scIRJ .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-5 rect,#mermaid-svg-fwYux79g7F3scIRJ .section-5 path,#mermaid-svg-fwYux79g7F3scIRJ .section-5 circle,#mermaid-svg-fwYux79g7F3scIRJ .section-5 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section-5 text{fill:black;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon-5{font-size:40px;color:black;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth-5{stroke-width:-1;}#mermaid-svg-fwYux79g7F3scIRJ .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-6 rect,#mermaid-svg-fwYux79g7F3scIRJ .section-6 path,#mermaid-svg-fwYux79g7F3scIRJ .section-6 circle,#mermaid-svg-fwYux79g7F3scIRJ .section-6 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section-6 text{fill:black;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon-6{font-size:40px;color:black;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth-6{stroke-width:-4;}#mermaid-svg-fwYux79g7F3scIRJ .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-7 rect,#mermaid-svg-fwYux79g7F3scIRJ .section-7 path,#mermaid-svg-fwYux79g7F3scIRJ .section-7 circle,#mermaid-svg-fwYux79g7F3scIRJ .section-7 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section-7 text{fill:black;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon-7{font-size:40px;color:black;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth-7{stroke-width:-7;}#mermaid-svg-fwYux79g7F3scIRJ .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-8 rect,#mermaid-svg-fwYux79g7F3scIRJ .section-8 path,#mermaid-svg-fwYux79g7F3scIRJ .section-8 circle,#mermaid-svg-fwYux79g7F3scIRJ .section-8 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section-8 text{fill:black;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon-8{font-size:40px;color:black;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth-8{stroke-width:-10;}#mermaid-svg-fwYux79g7F3scIRJ .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-9 rect,#mermaid-svg-fwYux79g7F3scIRJ .section-9 path,#mermaid-svg-fwYux79g7F3scIRJ .section-9 circle,#mermaid-svg-fwYux79g7F3scIRJ .section-9 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section-9 text{fill:black;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon-9{font-size:40px;color:black;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth-9{stroke-width:-13;}#mermaid-svg-fwYux79g7F3scIRJ .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-10 rect,#mermaid-svg-fwYux79g7F3scIRJ .section-10 path,#mermaid-svg-fwYux79g7F3scIRJ .section-10 circle,#mermaid-svg-fwYux79g7F3scIRJ .section-10 polygon,#mermaid-svg-fwYux79g7F3scIRJ .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section-10 text{fill:black;}#mermaid-svg-fwYux79g7F3scIRJ .node-icon-10{font-size:40px;color:black;}#mermaid-svg-fwYux79g7F3scIRJ .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .edge-depth-10{stroke-width:-16;}#mermaid-svg-fwYux79g7F3scIRJ .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-fwYux79g7F3scIRJ .disabled,#mermaid-svg-fwYux79g7F3scIRJ .disabled circle,#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:lightgray;}#mermaid-svg-fwYux79g7F3scIRJ .disabled text{fill:#efefef;}#mermaid-svg-fwYux79g7F3scIRJ .section-root rect,#mermaid-svg-fwYux79g7F3scIRJ .section-root path,#mermaid-svg-fwYux79g7F3scIRJ .section-root circle,#mermaid-svg-fwYux79g7F3scIRJ .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-fwYux79g7F3scIRJ .section-root text{fill:#ffffff;}#mermaid-svg-fwYux79g7F3scIRJ .section-root span{color:#ffffff;}#mermaid-svg-fwYux79g7F3scIRJ .section-2 span{color:#ffffff;}#mermaid-svg-fwYux79g7F3scIRJ .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-fwYux79g7F3scIRJ .edge{fill:none;}#mermaid-svg-fwYux79g7F3scIRJ .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-fwYux79g7F3scIRJ :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 接口测试实战
准备阶段
理解需求
分析接口文档
准备测试数据
执行阶段
按用例执行
记录结果
提交缺陷
回归阶段
验证修复
重跑用例
更新状态
课后练习 📝
-
实践题:使用Postman或curl,完成上述电商系统的接口测试。
-
扩展题:为支付模块设计测试用例(支付成功、支付失败、重复支付等)。
10.10 下章预告
下一章我们将学习接口参数化与数据驱动测试!
"理论是灰色的,而实践之树常青。------歌德"