DEV Community

Discussion on: Understanding Unit Test From The Best Book On The Topic

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

Hi Rex, nice post. I only disagree in a little phrase over that:

"Writing good tests is the only thing that can lead us to best practices, to suitable architectures and patterns."

I believe that are knowledge and experience which leads to best practices.

Architectures and patterns, on the other side, are meant to solve specific use cases so it's the ability to analyse the problem we're about to solve which lead us to the adequate architecture and/or pattern for this specific case.

I'll define tests as the key point that permit us to maintain and refactor our software without the deep fear of breaking other use-cases that we are not aware of (and thus, will not be manually tested).

A join statement for both things would be: "don't try to refactor and develop at the same time" because if you develop, you'll need to update the tests as well, in which case you'll never know if the reason for the tests being in red is either the refactor or the development (or both) or an even worse situation, the tests being in green just because the update you wrote on them 😆

This is for businesses people: remember that it's cheaper to have tests in the software than getting an entire QA team, for developers it's also quicker and easier to solve an issue prompted by the tests than dealing with other people and get stuck in emails and calls.

Best regards

Collapse
 
rexebin profile image
Rex • Edited

Thank you for your comment! You are absolutely right about the importance of testing and that we should not refactor/abstract too early. With testing, refactoring come naturally with comfort after green tests.

If done right, the process of writing testing is problem solving, which definitely leads to suitable architecture and pattern that make the testing easier and code cleaner.

I think knowledge and experience don’t necessarily lead to best practices. Knowledge and experience guided by testing however guarantees the best practices and is also a fast lane to writing good software.