Write the Tests
|
Code without tests is already broken.
tests make sure you're good to go, give you confidence, and save you a lot of time.
many developers think writing tests is a waste of time, but i'd say "they’re wrong".
Ive worked on different projects. I always had a good time working on tested code bases, and obviously a bad hard time with ones that had no tests.
It's just not easy task to work on existing code that has no tests (unit, integration or e2e). you can’t predict what your changes will affect.
sometimes, removing a single line breaks something completely unrelated and unexpected.
That’s why writing tests is really important.
It’s not just about making sure your code runs fine, tests also help make your code cleaner and more readable.
Good tests mean you’ve covered most of your logic, so if you change or remove something random (even if it looks unused), the tests will catch it.
from my experience, working on a project with no tests for the past year was really hard. I couldn’t improve the code safely. I had to manually test everything just to be sure it worked as expected.
- How to write tests? What approach should you Follow?
honestly, I don’t think it really matters, just start with something simple.
The most important thing is to test the core parts of your project, the base logic, the parts that everything else depends on.
For me, if I’m starting a new project, I usually go with unit tests. They're fast and focused, and they help you catch small issues early.
But if I’m working on a legacy project with no tests, I prefer to write integration or E2E tests first. why? Because you're usually testing real user use cases, not just internal logic. That way, you can make changes with more confidence, knowing the key flows are covered.
don’t overthink the structure at the beginning. just write one test that covers a real case, and build from there.
Thanks for reading! i’d love to hear your thoughts, do you agree with me? did I miss something? let me know what you think or how you approach testing.
Comments
Post a Comment