Wednesday, October 26, 2016

Side effects with not having decent UNIT tests

This is not Grails/Groovy specific but in general.

Grails/Groovy is certainly more reliant on tests, as it is dynamically typed, so code needs to be executed to pickup errors. The Java world seems to rely on static typing while Groovy on tests. Tests are always better than typing, period.

Besides the obvious, if it is not tested how do you know it works? There are some interesting side effects I see with poorly unit tested code.

Makes your Code Better

  • Having to write unit tests for a class/method makes your code structurally better.
  • It leads to better separation of concerns. 
  • Starts enforcing the law of Demeter. 
  • Easily tested code is generally easier to understand. 


Documents Code

  • Documentation falls out of date and quickly becomes irrelevant. Properly written tests (Spock helps) is a great way to document code. 


Makes changing existing code possible

  • I cannot change existing if I have no idea if it works, or how it works. 
  • In larger systems knowing if existing code works without tests becomes increasingly difficult.
  • It can be very difficult to execute see what code is doing if you need to stand up the whole system just to test a method.


Quicker to Change and Safer to Change

  • If your code has a unit test you can execute it immediately.
  • You can see changes, and what they do to existing tests immediately
  • 100's of times an hour.

No comments:

Post a Comment