DEV Community

Discussion on: Why practicing DRY in tests is bad for you

Collapse
 
gamma032steam profile image
Matthew Lui

I've been reading pragmatic programmer recently (the origin of the DRY principle). One thing the authors stress in the latest is edition is how what they wrote was misinterpreted. DRY is about having single sources of truth in a system. Two tests with different inputs have different intent - they do different things - so it's okay to copy-paste.

In this case I would think about how I expect the tests to be changed. Do I want to make it easy to add and remove tests? Write a loop and have an array of inputs that are passed in. Do I want the test itself to be easy to change? Keep it simple and copy-paste within reason.

Collapse
 
mbarzeev profile image
Matti Bar-Zeev

Totally! Thanks for the additional resource to back this up