📜 ⬆️ ⬇️

"I do not write unit tests, because ..." - excuses

I deeply believe in the TDD methodology (development through testing), as I have seen in practice the benefits of it. It brings software development to a new level of quality and maturity, although it has not yet become widespread. When it comes to choosing between functionality, time and quality, it is quality that always suffers. We usually do not want to spend more time on testing and do not want to make concessions in the amount of functionality produced. If you did not plan to use the TDD methodology from the very beginning of the project, then it is very difficult to switch to it.

We all heard many excuses why someone does not use TDD, but nowhere is there a better selection of excuses collected in one place than in the book " Pragmatic unit testing for Java using JUnit " from the series " Pragmatic Bookshelf ". I read this book a few years ago and thought that no one responsible developer after reading this book would be left without the feeling that unit testing is one of the most important aspects of a developer’s work.

The most disturbing excuse I've heard is “ my code is too difficult to test ”. There may be two explanations for this. One thing is that most of your code draws UI (user interface), and automating UI tests is too complicated. I agree that automating the testing of UI is difficult (although possible), but everything that is possible should be done to automate: think about regression tests. If you have a fully automated test suite, including the UI, you can always make new changes to the code, being completely sure that you haven't broken anything.
')
The second explanation is why your code is too difficult to test - your design is too confusing. Perhaps the logic and the UI-code are too closely related, and this dependence will complicate your life if you do not have an automatic UI-test. This is where unit testing helps create a good design. Using JUnit is very simple, so if I can only select a separate layer with logic and write tests for it, I can automatically test all the logic that the UI will ever use. What? You do not have a domain model? Then use stubs (mock objects) - there are many libraries for this.

For those who have not yet read this book, I will give a brief overview of the excuses why people do not use unit tests.



This book lists other excuses. but these are basic. And what excuses have you heard?

Source: https://habr.com/ru/post/112685/


All Articles