I'd only argue that DRY is a never compromising principle. If you have 3000 unit tests that are all copypasta and you refactor something they all touch it makes updating them all painful.
I agree. I recently had to decide this for myself and decided to err on the side of DRY. I decided that abstracting my tests made way more sense with respect to maintaining them than some concern about others using them to understand the API. That's what proper documentation and code examples are for. The ability for some tests to double as examples is handy but it shouldn't be done at the expense of maintainable test code.
2 comments
1 u/PuttItOut 22 May 2016 01:07
I'd only argue that DRY is a never compromising principle. If you have 3000 unit tests that are all copypasta and you refactor something they all touch it makes updating them all painful.
2 u/ForgotMyName 22 May 2016 06:13
I agree. I recently had to decide this for myself and decided to err on the side of DRY. I decided that abstracting my tests made way more sense with respect to maintaining them than some concern about others using them to understand the API. That's what proper documentation and code examples are for. The ability for some tests to double as examples is handy but it shouldn't be done at the expense of maintainable test code.