← 返回规律列表
质量

杀虫剂悖论

反复运行同一组测试,发现新缺陷的能力会逐渐下降。

显示原始英文内容

Pesticide Paradox

Repeatedly running the same tests becomes less effective over time.

Takeaways

  • Over time, an outdated test suite will identify fewer bugs. The tests are still helpful, but no longer effective at detecting new defects.
  • This paradox illustrates the need to infuse new test data continuously. It is essential for testers not to become complacent with their test scripts, thinking that these alone will be sufficient in the future.
  • By periodically creating new tests (by altering existing ones), you effectively 'refresh the pesticide,' thereby providing an opportunity to catch new bugs. This involves extending tests for new functionality, trying new input combinations, or perhaps just investigating new boundary cases.

Overview

The "Pesticide Paradox" analogy comes from agriculture. When the same pesticide is used repeatedly, pests develop resistance to it.

In software, the first runs of a new test suite might find many bugs. Those bugs get fixed. If you keep running the same tests without changes, you won't find more bugs there. The software has become "immune" to those specific tests.

The testing process cannot be stagnant. Test cases must be maintained regularly. After every release cycle, testers should assess which bugs made it to production and enhance the test suite accordingly.

This paradox also argues for exploratory testing, where testers approach the application in new ways each iteration, uncovering problems a static regression suite would miss. The paradox doesn't mean regression testing is useless, as old tests catch regressions. But to catch *new* bugs, you must design *new* tests.

Examples

Let's consider a mobile app where, in the first release, testers wrote extensive tests for the login and user profile features, finding and getting ten bugs fixed in those areas. In the subsequent releases, those test cases all pass (no new bugs in login or profile, great). Meanwhile, the app has added a messaging feature, but the test suite didn't add many cases for it. However, within a couple of releases, complaints started trickling in regarding the messaging functionality crashing. Unfortunately, the test suite failed to identify these because it was not updated to test messaging, which is predominantly centered on login and profile.

This is the pesticide paradox, which states that as testing became green (no defects remained in the code tested), new defects began to emerge, thereby requiring new tests. However, after the group includes their messaging tests, they begin to uncover these issues before they become releases. This process continues until those tests no longer find new issues, and the pattern repeats with the following features that emerge.

Origins

The concept was articulated by Dr. Boris Beizer, a software testing expert, and became widely known as one of the "seven principles of testing" in ISTQB (International Software Testing Qualifications Board) materials.

Beizer stated something to the effect of: every method of testing will yield a pesticide paradox, bugs adapt to tests, leaving more subtle bugs behind.

核心含义

固定测试只能覆盖它预先表达的场景。随着代码变化,旧测试可能继续通过,却无法发现新的边界、组合和用户行为。测试套件也需要持续维护、扩展和重构。

测试的价值不仅是数量,还在于是否覆盖了新的风险和失败方式。

实践例子

一个接口始终通过正常参数测试,但新增分页、权限和并发功能后没有相应案例。补充异常输入、越权访问和重复请求测试,才能让测试重新覆盖变化后的风险。

来源与边界

这个比喻来自软件测试领域,类似反复使用同一种杀虫剂后,害虫会逐渐产生抗性。它不要求不停增加测试,而是要求根据缺陷和系统变化更新测试策略。