知识卡片
零响应内容不能证明没有写入
要验证取消路径完全不接触响应,只比较空Body不足:写入空切片或设置头也可能没有正文。专用Spy分别在Header、Write、WriteHeader被调用时记录written,可观察这种交互;它是局部测试替身,Header返回nil等行为不能当完整可替换ResponseWriter实现。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
- · 上下文
原书出处 · 1 处
- 上下文 · 查看原书依据
type SpyResponseWriter struct { written bool } func (s *SpyResponseWriter) Header() http.Header { s.written = true return nil } func (s *SpyResponseWr
参考来源
- 位置:《通过测试学习 Go 编程》上下文,spine018(book-sources;extracted/通过测试学习 Go 编程/_epub-src/OEBPS/Text/17.html)。
- 结论依据:原文为禁止任何响应操作实现三个方法并断言written为false。
- 原始内容:type SpyResponseWriter struct { written bool } func (s *SpyResponseWriter) Header() http.Header { s.written = true return nil } func (s *SpyResponseWr