I have a situation where I have different forms, each with 4 or 5 steps (components), and I decided to write one unit test per step.
After doing it, I noticed they were very similar and I could just loop through them, changing some values based on the loop index. All good and worked fine, until one of the forms failed and I couldn't figure out which step was failing . I could provide another generic solution for it, but this failure made me wonder if it really makes sense to reuse code for tests like this.
Well... as developers, we always want to reduce code duplicates, but I think for unit/snapshot tests, it's a best practice to have every test explicit. The advantage I see by duplicating code in this situation is that it makes it more clear, easy to debug when a failure happens and also, once it's test code, it doesn't impact production code. What are your thoughts on it? Does it worth to have generic code to test several similar components, or is it better and safer to have it more explicit, even if you have to duplicate the code?
I also read this article on twitter, a few days ago that opened my mind for this approach even more: https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstraction WDYT?