知识卡片
本地替身验证HTTP契约
本地 HTTP 替身比只模拟函数返回值多覆盖一层协议行为。可验证方法、路径、编码后的参数、重试次数及客户端对状态码和响应体的处理。每个用例应拥有独立的端口与状态,并由调用者注入目标地址。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 11. Testing 本地 HTTP 替身检查协议 · 查看原书依据
Our mock has the endpoint /my-endpoint. Our mock also expects certain parameters in the URL. Our mock will return the response code of 201 with a body of world. We also expect our server to be hit five times. We can add more endpoints if we want, but for this example we are using only one to avoid bloating the chapter.
参考来源
- 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第11章《Chapter 11. Testing》,本地 HTTP 替身检查协议(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch11.html#id73)
- 结论依据:原书给 mock endpoint 指定查询匹配、响应与期望调用次数。
- 原始内容:Our mock has the endpoint /my-endpoint. Our mock also expects certain parameters in the URL. Our mock will return the response code of 201 with a body of world. We also expect our server to be hit five times. We can add more endpoints if we want, but for this example we are using only one to avoid bloating the chapter.