Mistake: Chasing 100% Coverage
找错误 中等
题目
什么是 错误使用这个测试策略?
代码
// Goal: 100% code coverage
// Adding tests just to cover lines
test('covers line 42', () => {
render(); // no assertions, just calls the function
});
提示
Coverage 不使用 assertions 是 meaningless.
解释
mistake 是 chasing 100% coverage 通过添加测试使用否 meaningful assertions. 测试那个只是 calls 函数到 'cover' 它 provides 否值 — 它 doesn't 验证 behavior. fix: focus on 测试 behavior and 边缘情况使用 meaningful assertions. Let coverage 是 byproduct 的好 测试, 不 goal 它自己.
相关资源
相关课程
- 测试 Coverage
Measuring and interpreting coverage.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。