Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Real life unit testing for small companies and applications

Tags:

unit-testing

In these typical business applications, written by small software companies (even solo), is there really any benefit in unit testing? (I'm talking about those typical custom made applications like an automated invoicing app.)

Mind you: I'm not questioning the benefits of unit testing (clean code, improve refactoring ability, etc.), but I'm questioning the ROI for small software applications. OK, you will win time chasing bugs, etc., but I do not seem to believe that you will win enough time to deal with the increase in time on developing the tests.

Please convince me otherwise, as I can see the benefit in it, only not for small software applications/companies for now.

PS: What are some real life examples of unit tests, as written in typical business applications? (invoicing, CRM, etc.)

like image 521
Tom Deleu Avatar asked Sep 15 '10 14:09

Tom Deleu


2 Answers

Here's how I see it paying off for small apps:

  • Your tests are a form of documentation on how your app is supposed to work. Makes life easier on you when you leave the app alone for a while or the next guy.
  • Your tests are good coverage when you just need to make that small change that you know won't break anything. Your tests will let you know quickly.
  • Many times in small apps the unit tests save you time in testing the UI of the app. AKA - How many times do you have to fire off the app to test that the input screen takes the correct information and spits out the correct information. This doesn't replace UI testing but it does save time in testing in general even on small apps.
  • How often do small apps grow. In my experience often enough. If you don't start unit tests early you are more likely to not do it later and/or take more time to cover the code that wasn't originally done. Now if you could just remember how that code was supposed to work in all cases.....hmmmm...
  • It's great practice for when you do absolutely see the value in doing it say on a larger project and hopefully be the better for it. :-)
  • The tests are a great way of helping you see if you have a design flaw and/or a better way to code something. The tests can/are a form of design and can really help one see if somethings a little clumsy / awkward.

Check out James Shore's youtube play by play of doing TDD on a very small application. Just watching him go through it and seeing and listening to him really helps show how TDD and unit testing can really be beneficial even in small apps.

like image 50
Kevin LaBranche Avatar answered Nov 04 '22 00:11

Kevin LaBranche


Let's see,

  1. If your small app is used in a very critical portion of your client's stack then it's very important that you come away with near perfectly functioning code.
  2. If that small app is used to balance their receivables, I bet they want to know for sure that the formulas used are correct. No business wants to give out freebies or "lose" money.
  3. If your app exposes an API so that it can be expanded and assimilated within another application, you'll want unit tests to verify that you did it right, their engineer is screwing it up. (Oh yes, for a small 1000 line piece of code that really did save my butt.)
  4. If your small app will get passed onto someone else to maintain it. They'll thank you for it.
  5. If you come away with some functionality you'd like to use elsewhere in a larger app having the pre-generated unit tests will save both time and headache. Imagine tiny bug that doesn't impact your small app very much getting into a larger app where it could cause substantial damage.

In short there's a myriad number of use cases where I could see that unit tests pay off even for a small, non-trival app. Check out klabranche's video linked there. Excellent.

like image 22
wheaties Avatar answered Nov 04 '22 00:11

wheaties