Readplace

When Code Duplication Is Acceptable

fagnerbrack.com 5 min read
View original
Summary (TL;DR)
The article argues that code duplication is less harmful in test code than in production code. Tests should be simple, declarative, and follow the Arrange-Act-Assert model. While duplication in production code is a bad smell due to maintenance risks, duplicating steps like the 'Act' in tests can improve clarity and intent. Abstraction in tests should only be used for test concerns, not test code itself. Over-abstraction can obscure test purpose and add complexity. The key is to balance duplication with readability, as DRY is not a rigid rule.