
We, as developers, always try to make the best code possible, right?
Typically some of the topics below are what we have in mind when developing:
1. Well-structured code
2. Clear/Readable Code
3. Using DRY (Don't Repeat Yourself)
4. Applying the S.O.L.I.D.
This is all great, and you need to think about developing with some of these topics in mind. But I've noticed that concern is almost non-existent when we do test codes.
Why are tests treated differently? Why not think about coding with the same thinking as the main code?
The fact is, test codes are just as important as core ones. When we need to add some new functionality or expand on the existing one, we'll need to update the tests. And if it's all messed up, contexts that don't make much sense, duplications, full of code smells, it won't be easy to add the new past requirement. Usually, it will take a lot more work to understand the tests than the main code and also take longer to add new contexts and expectations for a test like this.
Typically, developers ignore the existing tests when they see them as described above. Instead, they add the new requirements to the main code and hope the tests still pass.
But imagine if the tests pass, how many false/positives can appear, and how much new information and logic are not being validated. The test ends up becoming obsolete. Until the time comes when no one else wants to add anything and delete the test because it's breaking.
That's not being careful with your code. Tests belong to the heart of development. They are the ones who will give you a greater guarantee of the application, security to refactor/add new requirements with more dexterity/agility, and without fear of touching something in point A that negatively influences point B.
Conclusion
Remember that testing is just as important/necessary as your core code. Therefore, develop test codes with the same mindset that you do with the core code.
Well-written code, main and tests, will always make it easier to expand your application more assertively, faster, and with higher quality.
That's the importance of having your tests organized and well structured.
Thanks