DEV Community

Discussion on: Stop Writing DRY Code

peerreynders profile image

A good example is tests

Tests have different priorities - Tests Too DRY? Make Them DAMP!:

"Since tests don't have tests, it should be easy for humans to manually inspect them for correctness, even at the expense of greater code duplication. …which emphasizes readability over uniqueness"

and yet

"the DRY principle is still relevant in tests; for example, using a helper function for creating value objects can increase clarity by removing redundant details from the test body."

The challenge is to keep inappropriate coupling (resulting from overzealous DRY) out of tests because that can lead to fragile tests.