09 接口测试用例设计 – 测试的艺术
🎯 本章目标:掌握接口测试用例设计方法,学会用等价类、边界值、场景法等设计全面的测试用例。
9.1 为什么用例设计很重要
生活中的例子
想象你要测试一个电梯系统:
如果只测试"正常上楼" → 漏掉了超载、停电、故障等场景
如果测试所有可能 → 时间不够,成本太高
好的用例设计 = 用最少的时间,覆盖最重要的场景
接口测试用例设计原则
#mermaid-svg-6OWjPpO9lb3e036a{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-6OWjPpO9lb3e036a .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-6OWjPpO9lb3e036a .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-6OWjPpO9lb3e036a .error-icon{fill:#552222;}#mermaid-svg-6OWjPpO9lb3e036a .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-6OWjPpO9lb3e036a .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-6OWjPpO9lb3e036a .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-6OWjPpO9lb3e036a .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-6OWjPpO9lb3e036a .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-6OWjPpO9lb3e036a .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-6OWjPpO9lb3e036a .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-6OWjPpO9lb3e036a .marker{fill:#333333;stroke:#333333;}#mermaid-svg-6OWjPpO9lb3e036a .marker.cross{stroke:#333333;}#mermaid-svg-6OWjPpO9lb3e036a svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-6OWjPpO9lb3e036a p{margin:0;}#mermaid-svg-6OWjPpO9lb3e036a .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-6OWjPpO9lb3e036a .cluster-label text{fill:#333;}#mermaid-svg-6OWjPpO9lb3e036a .cluster-label span{color:#333;}#mermaid-svg-6OWjPpO9lb3e036a .cluster-label span p{background-color:transparent;}#mermaid-svg-6OWjPpO9lb3e036a .label text,#mermaid-svg-6OWjPpO9lb3e036a span{fill:#333;color:#333;}#mermaid-svg-6OWjPpO9lb3e036a .node rect,#mermaid-svg-6OWjPpO9lb3e036a .node circle,#mermaid-svg-6OWjPpO9lb3e036a .node ellipse,#mermaid-svg-6OWjPpO9lb3e036a .node polygon,#mermaid-svg-6OWjPpO9lb3e036a .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-6OWjPpO9lb3e036a .rough-node .label text,#mermaid-svg-6OWjPpO9lb3e036a .node .label text,#mermaid-svg-6OWjPpO9lb3e036a .image-shape .label,#mermaid-svg-6OWjPpO9lb3e036a .icon-shape .label{text-anchor:middle;}#mermaid-svg-6OWjPpO9lb3e036a .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-6OWjPpO9lb3e036a .rough-node .label,#mermaid-svg-6OWjPpO9lb3e036a .node .label,#mermaid-svg-6OWjPpO9lb3e036a .image-shape .label,#mermaid-svg-6OWjPpO9lb3e036a .icon-shape .label{text-align:center;}#mermaid-svg-6OWjPpO9lb3e036a .node.clickable{cursor:pointer;}#mermaid-svg-6OWjPpO9lb3e036a .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-6OWjPpO9lb3e036a .arrowheadPath{fill:#333333;}#mermaid-svg-6OWjPpO9lb3e036a .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-6OWjPpO9lb3e036a .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-6OWjPpO9lb3e036a .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-6OWjPpO9lb3e036a .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-6OWjPpO9lb3e036a .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-6OWjPpO9lb3e036a .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-6OWjPpO9lb3e036a .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-6OWjPpO9lb3e036a .cluster text{fill:#333;}#mermaid-svg-6OWjPpO9lb3e036a .cluster span{color:#333;}#mermaid-svg-6OWjPpO9lb3e036a 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-6OWjPpO9lb3e036a .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-6OWjPpO9lb3e036a rect.text{fill:none;stroke-width:0;}#mermaid-svg-6OWjPpO9lb3e036a .icon-shape,#mermaid-svg-6OWjPpO9lb3e036a .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-6OWjPpO9lb3e036a .icon-shape p,#mermaid-svg-6OWjPpO9lb3e036a .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-6OWjPpO9lb3e036a .icon-shape .label rect,#mermaid-svg-6OWjPpO9lb3e036a .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-6OWjPpO9lb3e036a .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-6OWjPpO9lb3e036a .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-6OWjPpO9lb3e036a :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
用例设计原则
全面性
代表性
可执行性
可维护性
覆盖正常和异常
避免冗余
步骤清晰
易于更新
9.2 等价类划分法
什么是等价类
等价类:把输入数据划分为若干类,每类中的数据在测试中的作用等价,只需从每类中选一个代表测试。
例子:年龄输入框
需求:年龄范围 1-150
有效等价类(有效数据):
├─ 1-150 之间的整数
无效等价类(无效数据):
├─ 小于1(0, -1, -100)
├─ 大于150(151, 200, 999)
├─ 非整数(1.5, "abc")
└─ 空值
接口测试中的应用
场景:用户注册接口,用户名长度 3-20 位
| 有效:3-20位 | “abc” | 成功 |
| 有效:3-20位 | “abcdefghijklmnopqrs” | 成功 |
| 无效:小于3位 | “ab” | 错误 |
| 无效:大于20位 | “abcdefghijklmnopqrstu” | 错误 |
| 无效:空值 | “” | 错误 |
| 无效:特殊字符 | “ab@c” | 错误 |
9.3 边界值分析法
什么是边界值
边界值:错误往往发生在输入范围的边界上,因此需要重点测试边界及边界附近的值。
边界值选取规则
如果范围是 [min, max],测试:
– min – 1(略低于最小值)
– min(最小值)
– min + 1(略高于最小值)
– max – 1(略低于最大值)
– max(最大值)
– max + 1(略高于最大值)
例子:分页接口
需求:page 范围 1-100,size 范围 1-50
边界值测试:
page: 0, 1, 2, 99, 100, 101
size: 0, 1, 2, 49, 50, 51
接口测试中的应用
场景:获取商品列表,page: 1-1000, size: 1-100
| page最小值 | page=1 | 返回第一页 |
| page最小值-1 | page=0 | 错误或默认第一页 |
| page最大值 | page=1000 | 返回第1000页 |
| page最大值+1 | page=1001 | 错误或空列表 |
| size最小值 | size=1 | 返回1条 |
| size最大值 | size=100 | 返回100条 |
| size最大值+1 | size=101 | 错误或限制为100 |
9.4 场景法(流程分析法)
什么是场景法
场景法:根据业务流程设计测试用例,覆盖完整的业务场景。
电商下单场景
#mermaid-svg-IG632NMG5NaqyxLd{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-IG632NMG5NaqyxLd .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-IG632NMG5NaqyxLd .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-IG632NMG5NaqyxLd .error-icon{fill:#552222;}#mermaid-svg-IG632NMG5NaqyxLd .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-IG632NMG5NaqyxLd .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-IG632NMG5NaqyxLd .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-IG632NMG5NaqyxLd .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-IG632NMG5NaqyxLd .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-IG632NMG5NaqyxLd .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-IG632NMG5NaqyxLd .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-IG632NMG5NaqyxLd .marker{fill:#333333;stroke:#333333;}#mermaid-svg-IG632NMG5NaqyxLd .marker.cross{stroke:#333333;}#mermaid-svg-IG632NMG5NaqyxLd svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-IG632NMG5NaqyxLd p{margin:0;}#mermaid-svg-IG632NMG5NaqyxLd .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-IG632NMG5NaqyxLd .cluster-label text{fill:#333;}#mermaid-svg-IG632NMG5NaqyxLd .cluster-label span{color:#333;}#mermaid-svg-IG632NMG5NaqyxLd .cluster-label span p{background-color:transparent;}#mermaid-svg-IG632NMG5NaqyxLd .label text,#mermaid-svg-IG632NMG5NaqyxLd span{fill:#333;color:#333;}#mermaid-svg-IG632NMG5NaqyxLd .node rect,#mermaid-svg-IG632NMG5NaqyxLd .node circle,#mermaid-svg-IG632NMG5NaqyxLd .node ellipse,#mermaid-svg-IG632NMG5NaqyxLd .node polygon,#mermaid-svg-IG632NMG5NaqyxLd .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-IG632NMG5NaqyxLd .rough-node .label text,#mermaid-svg-IG632NMG5NaqyxLd .node .label text,#mermaid-svg-IG632NMG5NaqyxLd .image-shape .label,#mermaid-svg-IG632NMG5NaqyxLd .icon-shape .label{text-anchor:middle;}#mermaid-svg-IG632NMG5NaqyxLd .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-IG632NMG5NaqyxLd .rough-node .label,#mermaid-svg-IG632NMG5NaqyxLd .node .label,#mermaid-svg-IG632NMG5NaqyxLd .image-shape .label,#mermaid-svg-IG632NMG5NaqyxLd .icon-shape .label{text-align:center;}#mermaid-svg-IG632NMG5NaqyxLd .node.clickable{cursor:pointer;}#mermaid-svg-IG632NMG5NaqyxLd .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-IG632NMG5NaqyxLd .arrowheadPath{fill:#333333;}#mermaid-svg-IG632NMG5NaqyxLd .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-IG632NMG5NaqyxLd .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-IG632NMG5NaqyxLd .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-IG632NMG5NaqyxLd .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-IG632NMG5NaqyxLd .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-IG632NMG5NaqyxLd .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-IG632NMG5NaqyxLd .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-IG632NMG5NaqyxLd .cluster text{fill:#333;}#mermaid-svg-IG632NMG5NaqyxLd .cluster span{color:#333;}#mermaid-svg-IG632NMG5NaqyxLd 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-IG632NMG5NaqyxLd .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-IG632NMG5NaqyxLd rect.text{fill:none;stroke-width:0;}#mermaid-svg-IG632NMG5NaqyxLd .icon-shape,#mermaid-svg-IG632NMG5NaqyxLd .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-IG632NMG5NaqyxLd .icon-shape p,#mermaid-svg-IG632NMG5NaqyxLd .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-IG632NMG5NaqyxLd .icon-shape .label rect,#mermaid-svg-IG632NMG5NaqyxLd .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-IG632NMG5NaqyxLd .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-IG632NMG5NaqyxLd .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-IG632NMG5NaqyxLd :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
是
否
是
否
开始
浏览商品
加入购物车
提交订单
库存充足?
支付
提示缺货
支付成功?
订单完成
支付失败
取消订单
结束
场景用例设计
| 正常下单 | 浏览→加购→提交→支付 | 订单成功 |
| 库存不足 | 浏览→加购→提交(库存不足) | 提示缺货 |
| 支付失败 | 浏览→加购→提交→支付失败 | 订单待支付 |
| 重复提交 | 快速连续提交两次 | 只生成一个订单 |
9.5 错误推断法
什么是错误推断
错误推断法:基于经验和直觉,推测程序中可能存在的错误,有针对性地设计测试用例。
常见接口错误
#mermaid-svg-BsWwYnEepoWPqhKf{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-BsWwYnEepoWPqhKf .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-BsWwYnEepoWPqhKf .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-BsWwYnEepoWPqhKf .error-icon{fill:#552222;}#mermaid-svg-BsWwYnEepoWPqhKf .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-BsWwYnEepoWPqhKf .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-BsWwYnEepoWPqhKf .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-BsWwYnEepoWPqhKf .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-BsWwYnEepoWPqhKf .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-BsWwYnEepoWPqhKf .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-BsWwYnEepoWPqhKf .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-BsWwYnEepoWPqhKf .marker{fill:#333333;stroke:#333333;}#mermaid-svg-BsWwYnEepoWPqhKf .marker.cross{stroke:#333333;}#mermaid-svg-BsWwYnEepoWPqhKf svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-BsWwYnEepoWPqhKf p{margin:0;}#mermaid-svg-BsWwYnEepoWPqhKf .edge{stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .section–1 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section–1 path,#mermaid-svg-BsWwYnEepoWPqhKf .section–1 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section–1 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section–1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section–1 text{fill:#ffffff;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon–1{font-size:40px;color:#ffffff;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge–1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth–1{stroke-width:17;}#mermaid-svg-BsWwYnEepoWPqhKf .section–1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-0 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-0 path,#mermaid-svg-BsWwYnEepoWPqhKf .section-0 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-0 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-0 text{fill:black;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon-0{font-size:40px;color:black;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth-0{stroke-width:14;}#mermaid-svg-BsWwYnEepoWPqhKf .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-1 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-1 path,#mermaid-svg-BsWwYnEepoWPqhKf .section-1 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-1 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-1 text{fill:black;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon-1{font-size:40px;color:black;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth-1{stroke-width:11;}#mermaid-svg-BsWwYnEepoWPqhKf .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-2 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-2 path,#mermaid-svg-BsWwYnEepoWPqhKf .section-2 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-2 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-2 text{fill:#ffffff;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth-2{stroke-width:8;}#mermaid-svg-BsWwYnEepoWPqhKf .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-3 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-3 path,#mermaid-svg-BsWwYnEepoWPqhKf .section-3 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-3 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-3 text{fill:black;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon-3{font-size:40px;color:black;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth-3{stroke-width:5;}#mermaid-svg-BsWwYnEepoWPqhKf .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-4 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-4 path,#mermaid-svg-BsWwYnEepoWPqhKf .section-4 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-4 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-4 text{fill:black;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon-4{font-size:40px;color:black;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth-4{stroke-width:2;}#mermaid-svg-BsWwYnEepoWPqhKf .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-5 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-5 path,#mermaid-svg-BsWwYnEepoWPqhKf .section-5 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-5 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-5 text{fill:black;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon-5{font-size:40px;color:black;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth-5{stroke-width:-1;}#mermaid-svg-BsWwYnEepoWPqhKf .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-6 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-6 path,#mermaid-svg-BsWwYnEepoWPqhKf .section-6 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-6 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-6 text{fill:black;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon-6{font-size:40px;color:black;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth-6{stroke-width:-4;}#mermaid-svg-BsWwYnEepoWPqhKf .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-7 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-7 path,#mermaid-svg-BsWwYnEepoWPqhKf .section-7 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-7 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-7 text{fill:black;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon-7{font-size:40px;color:black;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth-7{stroke-width:-7;}#mermaid-svg-BsWwYnEepoWPqhKf .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-8 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-8 path,#mermaid-svg-BsWwYnEepoWPqhKf .section-8 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-8 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-8 text{fill:black;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon-8{font-size:40px;color:black;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth-8{stroke-width:-10;}#mermaid-svg-BsWwYnEepoWPqhKf .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-9 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-9 path,#mermaid-svg-BsWwYnEepoWPqhKf .section-9 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-9 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-9 text{fill:black;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon-9{font-size:40px;color:black;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth-9{stroke-width:-13;}#mermaid-svg-BsWwYnEepoWPqhKf .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-10 rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-10 path,#mermaid-svg-BsWwYnEepoWPqhKf .section-10 circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-10 polygon,#mermaid-svg-BsWwYnEepoWPqhKf .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-10 text{fill:black;}#mermaid-svg-BsWwYnEepoWPqhKf .node-icon-10{font-size:40px;color:black;}#mermaid-svg-BsWwYnEepoWPqhKf .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .edge-depth-10{stroke-width:-16;}#mermaid-svg-BsWwYnEepoWPqhKf .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled,#mermaid-svg-BsWwYnEepoWPqhKf .disabled circle,#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:lightgray;}#mermaid-svg-BsWwYnEepoWPqhKf .disabled text{fill:#efefef;}#mermaid-svg-BsWwYnEepoWPqhKf .section-root rect,#mermaid-svg-BsWwYnEepoWPqhKf .section-root path,#mermaid-svg-BsWwYnEepoWPqhKf .section-root circle,#mermaid-svg-BsWwYnEepoWPqhKf .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-BsWwYnEepoWPqhKf .section-root text{fill:#ffffff;}#mermaid-svg-BsWwYnEepoWPqhKf .section-root span{color:#ffffff;}#mermaid-svg-BsWwYnEepoWPqhKf .section-2 span{color:#ffffff;}#mermaid-svg-BsWwYnEepoWPqhKf .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-BsWwYnEepoWPqhKf .edge{fill:none;}#mermaid-svg-BsWwYnEepoWPqhKf .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-BsWwYnEepoWPqhKf :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
常见接口错误
参数问题
缺少必填参数
参数类型错误
参数长度超限
特殊字符注入
业务逻辑
重复提交
并发冲突
状态流转错误
权限绕过
异常情况
超时处理
空值处理
大数据量
服务不可用
错误推断用例示例
| SQL注入 | 用户名输入 ' OR 1=1 — | 拒绝或转义 |
| XSS攻击 | 输入 <script>alert(1)</script> | 转义或拒绝 |
| 重复请求 | 同一订单号提交两次 | 幂等处理 |
| 并发扣款 | 同时发起两次扣款 | 只扣一次 |
9.6 接口测试用例模板
标准用例模板
用例编号: API-USER-001
用例标题: 正常创建用户
接口路径: POST /api/v1/users
优先级: P1(高)
前置条件: 数据库已连接,用户表为空
请求参数:
{
"username": "testuser",
"email": "test@example.com",
"password": "123456"
}
预期结果:
状态码: 201
响应体:
{
"code": 0,
"message": "创建成功",
"data": {
"id": 1,
"username": "testuser",
"email": "test@example.com"
}
}
实际结果: (执行时填写)
测试状态: Pass/Fail/Block
用例设计检查清单
| 正常场景 | 所有必填参数正确 |
| 必填参数缺失 | 逐个缺少必填参数 |
| 参数类型错误 | 字符串传数字,数字传字符串 |
| 参数边界值 | 最小值、最大值、边界外 |
| 特殊字符 | 中文、表情、HTML标签 |
| 并发场景 | 同时多次调用 |
| 权限验证 | 未登录、无权限 |
| 重复操作 | 重复提交、幂等性 |
9.7 实战:用户管理接口用例设计
接口信息
POST /api/v1/users
功能: 创建用户
参数:
– username: 用户名,3-20位,必填
– email: 邮箱,必填
– password: 密码,6-20位,必填
– role: 角色,可选,默认user
用例设计
#mermaid-svg-jznkKAqUVg3tigRx{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-jznkKAqUVg3tigRx .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-jznkKAqUVg3tigRx .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-jznkKAqUVg3tigRx .error-icon{fill:#552222;}#mermaid-svg-jznkKAqUVg3tigRx .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-jznkKAqUVg3tigRx .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-jznkKAqUVg3tigRx .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-jznkKAqUVg3tigRx .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-jznkKAqUVg3tigRx .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-jznkKAqUVg3tigRx .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-jznkKAqUVg3tigRx .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-jznkKAqUVg3tigRx .marker{fill:#333333;stroke:#333333;}#mermaid-svg-jznkKAqUVg3tigRx .marker.cross{stroke:#333333;}#mermaid-svg-jznkKAqUVg3tigRx svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-jznkKAqUVg3tigRx p{margin:0;}#mermaid-svg-jznkKAqUVg3tigRx .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-jznkKAqUVg3tigRx .cluster-label text{fill:#333;}#mermaid-svg-jznkKAqUVg3tigRx .cluster-label span{color:#333;}#mermaid-svg-jznkKAqUVg3tigRx .cluster-label span p{background-color:transparent;}#mermaid-svg-jznkKAqUVg3tigRx .label text,#mermaid-svg-jznkKAqUVg3tigRx span{fill:#333;color:#333;}#mermaid-svg-jznkKAqUVg3tigRx .node rect,#mermaid-svg-jznkKAqUVg3tigRx .node circle,#mermaid-svg-jznkKAqUVg3tigRx .node ellipse,#mermaid-svg-jznkKAqUVg3tigRx .node polygon,#mermaid-svg-jznkKAqUVg3tigRx .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-jznkKAqUVg3tigRx .rough-node .label text,#mermaid-svg-jznkKAqUVg3tigRx .node .label text,#mermaid-svg-jznkKAqUVg3tigRx .image-shape .label,#mermaid-svg-jznkKAqUVg3tigRx .icon-shape .label{text-anchor:middle;}#mermaid-svg-jznkKAqUVg3tigRx .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-jznkKAqUVg3tigRx .rough-node .label,#mermaid-svg-jznkKAqUVg3tigRx .node .label,#mermaid-svg-jznkKAqUVg3tigRx .image-shape .label,#mermaid-svg-jznkKAqUVg3tigRx .icon-shape .label{text-align:center;}#mermaid-svg-jznkKAqUVg3tigRx .node.clickable{cursor:pointer;}#mermaid-svg-jznkKAqUVg3tigRx .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-jznkKAqUVg3tigRx .arrowheadPath{fill:#333333;}#mermaid-svg-jznkKAqUVg3tigRx .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-jznkKAqUVg3tigRx .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-jznkKAqUVg3tigRx .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-jznkKAqUVg3tigRx .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-jznkKAqUVg3tigRx .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-jznkKAqUVg3tigRx .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-jznkKAqUVg3tigRx .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-jznkKAqUVg3tigRx .cluster text{fill:#333;}#mermaid-svg-jznkKAqUVg3tigRx .cluster span{color:#333;}#mermaid-svg-jznkKAqUVg3tigRx 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-jznkKAqUVg3tigRx .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-jznkKAqUVg3tigRx rect.text{fill:none;stroke-width:0;}#mermaid-svg-jznkKAqUVg3tigRx .icon-shape,#mermaid-svg-jznkKAqUVg3tigRx .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-jznkKAqUVg3tigRx .icon-shape p,#mermaid-svg-jznkKAqUVg3tigRx .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-jznkKAqUVg3tigRx .icon-shape .label rect,#mermaid-svg-jznkKAqUVg3tigRx .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-jznkKAqUVg3tigRx .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-jznkKAqUVg3tigRx .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-jznkKAqUVg3tigRx :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
创建用户用例
正常场景
参数校验
业务规则
异常场景
所有参数正确
只传必填参数
用户名边界值
密码边界值
邮箱格式
缺少必填参数
重复用户名
重复邮箱
SQL注入
XSS攻击
超长参数
详细用例
| USER-001 | 正常创建 | 所有参数正确 | 201,用户创建成功 |
| USER-002 | 最小用户名 | username=“abc” | 201 |
| USER-003 | 最大用户名 | username=“abcdefghijklmnopqrs” | 201 |
| USER-004 | 用户名过短 | username=“ab” | 400,用户名长度错误 |
| USER-005 | 用户名过长 | username=“abcdefghijklmnopqrstu” | 400 |
| USER-006 | 缺少用户名 | 不传username | 400,参数缺失 |
| USER-007 | 邮箱格式错误 | email=“not-an-email” | 400 |
| USER-008 | 重复用户名 | 已存在的username | 409,用户名已存在 |
| USER-009 | SQL注入 | username=“’ OR 1=1” | 400或安全处理 |
| USER-010 | XSS攻击 | username=“” | 转义或拒绝 |
9.8 本章小结
用例设计方法总结
#mermaid-svg-b01PCKyqwi0KuWPE{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-b01PCKyqwi0KuWPE .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-b01PCKyqwi0KuWPE .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-b01PCKyqwi0KuWPE .error-icon{fill:#552222;}#mermaid-svg-b01PCKyqwi0KuWPE .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-b01PCKyqwi0KuWPE .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-b01PCKyqwi0KuWPE .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-b01PCKyqwi0KuWPE .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-b01PCKyqwi0KuWPE .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-b01PCKyqwi0KuWPE .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-b01PCKyqwi0KuWPE .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-b01PCKyqwi0KuWPE .marker{fill:#333333;stroke:#333333;}#mermaid-svg-b01PCKyqwi0KuWPE .marker.cross{stroke:#333333;}#mermaid-svg-b01PCKyqwi0KuWPE svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-b01PCKyqwi0KuWPE p{margin:0;}#mermaid-svg-b01PCKyqwi0KuWPE .edge{stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .section–1 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section–1 path,#mermaid-svg-b01PCKyqwi0KuWPE .section–1 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section–1 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section–1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section–1 text{fill:#ffffff;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon–1{font-size:40px;color:#ffffff;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge–1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth–1{stroke-width:17;}#mermaid-svg-b01PCKyqwi0KuWPE .section–1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-0 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-0 path,#mermaid-svg-b01PCKyqwi0KuWPE .section-0 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-0 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-0 text{fill:black;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon-0{font-size:40px;color:black;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth-0{stroke-width:14;}#mermaid-svg-b01PCKyqwi0KuWPE .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-1 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-1 path,#mermaid-svg-b01PCKyqwi0KuWPE .section-1 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-1 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-1 text{fill:black;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon-1{font-size:40px;color:black;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth-1{stroke-width:11;}#mermaid-svg-b01PCKyqwi0KuWPE .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-2 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-2 path,#mermaid-svg-b01PCKyqwi0KuWPE .section-2 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-2 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-2 text{fill:#ffffff;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth-2{stroke-width:8;}#mermaid-svg-b01PCKyqwi0KuWPE .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-3 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-3 path,#mermaid-svg-b01PCKyqwi0KuWPE .section-3 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-3 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-3 text{fill:black;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon-3{font-size:40px;color:black;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth-3{stroke-width:5;}#mermaid-svg-b01PCKyqwi0KuWPE .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-4 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-4 path,#mermaid-svg-b01PCKyqwi0KuWPE .section-4 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-4 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-4 text{fill:black;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon-4{font-size:40px;color:black;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth-4{stroke-width:2;}#mermaid-svg-b01PCKyqwi0KuWPE .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-5 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-5 path,#mermaid-svg-b01PCKyqwi0KuWPE .section-5 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-5 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-5 text{fill:black;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon-5{font-size:40px;color:black;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth-5{stroke-width:-1;}#mermaid-svg-b01PCKyqwi0KuWPE .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-6 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-6 path,#mermaid-svg-b01PCKyqwi0KuWPE .section-6 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-6 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-6 text{fill:black;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon-6{font-size:40px;color:black;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth-6{stroke-width:-4;}#mermaid-svg-b01PCKyqwi0KuWPE .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-7 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-7 path,#mermaid-svg-b01PCKyqwi0KuWPE .section-7 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-7 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-7 text{fill:black;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon-7{font-size:40px;color:black;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth-7{stroke-width:-7;}#mermaid-svg-b01PCKyqwi0KuWPE .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-8 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-8 path,#mermaid-svg-b01PCKyqwi0KuWPE .section-8 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-8 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-8 text{fill:black;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon-8{font-size:40px;color:black;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth-8{stroke-width:-10;}#mermaid-svg-b01PCKyqwi0KuWPE .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-9 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-9 path,#mermaid-svg-b01PCKyqwi0KuWPE .section-9 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-9 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-9 text{fill:black;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon-9{font-size:40px;color:black;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth-9{stroke-width:-13;}#mermaid-svg-b01PCKyqwi0KuWPE .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-10 rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-10 path,#mermaid-svg-b01PCKyqwi0KuWPE .section-10 circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-10 polygon,#mermaid-svg-b01PCKyqwi0KuWPE .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-10 text{fill:black;}#mermaid-svg-b01PCKyqwi0KuWPE .node-icon-10{font-size:40px;color:black;}#mermaid-svg-b01PCKyqwi0KuWPE .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .edge-depth-10{stroke-width:-16;}#mermaid-svg-b01PCKyqwi0KuWPE .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled,#mermaid-svg-b01PCKyqwi0KuWPE .disabled circle,#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:lightgray;}#mermaid-svg-b01PCKyqwi0KuWPE .disabled text{fill:#efefef;}#mermaid-svg-b01PCKyqwi0KuWPE .section-root rect,#mermaid-svg-b01PCKyqwi0KuWPE .section-root path,#mermaid-svg-b01PCKyqwi0KuWPE .section-root circle,#mermaid-svg-b01PCKyqwi0KuWPE .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-b01PCKyqwi0KuWPE .section-root text{fill:#ffffff;}#mermaid-svg-b01PCKyqwi0KuWPE .section-root span{color:#ffffff;}#mermaid-svg-b01PCKyqwi0KuWPE .section-2 span{color:#ffffff;}#mermaid-svg-b01PCKyqwi0KuWPE .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-b01PCKyqwi0KuWPE .edge{fill:none;}#mermaid-svg-b01PCKyqwi0KuWPE .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-b01PCKyqwi0KuWPE :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
用例设计
等价类划分
有效等价类
无效等价类
减少用例数量
边界值分析
最小值
最大值
边界外
场景法
正常流程
异常分支
业务覆盖
错误推断
经验推测
常见错误
安全测试
课后练习 📝
设计题:为登录接口设计测试用例(参数:username, password)。
分析题:分析你工作中的接口,用等价类和边界值设计用例。
9.9 下章预告
下一章我们将进行接口功能测试实战,把用例设计应用到实际测试中!
“好的测试用例设计,就像好的侦探工作——找到最关键的线索,而不是检查每一个角落。”



