Skip to content

Regression

一句话解释

regression 是当 code 那个 used 到工作停止工作之后更改. 测试 exist 到 catch regressions.

用大白话说

regression 是 bug 那个 introduces 失败 in functionality 那个 previously 工作. 你更改 code for one reason, and accidentally break 某事 else — 那个's regression.

Regressions 是主要 enemy 那个测试 fights. 不使用测试, 你可能更改函数 and unknowingly break another 函数那个 depends on 它. bug 可能不 surface 直到用户 encounters 它 in production.

With 测试, regressions 是 caught immediately. 当你 更改 code and 运行测试 suite, 任何测试那个是 passing 之前 and 现在失败 indicates regression. 你 know 正确远离什么你 broke and 能 fix 它之前 code reaches production.

This 是为什么我们 say 测试 'catch regressions' — 它们 prevent previously 工作 behavior 从 breaking. regression 测试是 特定地测试编写到 验证那个 previously fixed bug doesn't reappear.

示例

javascript
// Regression test — ensures a fixed bug stays fixed

// Bug: abs() returned wrong value for zero
// Fix commit: "fix: abs(0) should return 0"

test('regression: abs(0) returns 0 (bug #42)', () => {
  expect(abs(0)).toBe(0);  // This test prevents bug #42 from returning
});

// Run the full suite after any change:
// $ npm test
//  ✓ regression: abs(0) returns 0 (bug #42)
//  152 passing
// If someone reintroduces the bug, this test fails immediately.

回归测试锁住已修复的 bug 防止其重现。测试引用 bug 编号并验证修复;如果有人重新引入该 bug,测试会立即失败。

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表