Code duplication is repeated or similar code—or repeated responsibilities—in multiple places. It makes software harder to change: when logic is duplicated, a fix can be missed in one place and defects can follow. section 1.1.1 section 1.3.3
Look for duplication in tests as well as production code:
- Tests may repeat setup or cover the same behavior. Share common setup and remove redundant tests while preserving the specific behavior each test needs to check. section 2.4.2 section 2.4
- When tests repeat creating and parsing a template, move that work into a helper method so the tests focus on their assertions. section 3.2.1
See how redundant template-engine tests are removed and the remaining tests use a common template and setup. section 2.4.2
Refactor in small steps, and keep behavior unchanged. A useful check is whether a proposed cleanup removes repetition while leaving the tests focused on the functionality they verify. section 1.3.3 section 3.2.1




