DEV Community

Discussion on: The Short Term Benefits of Unit Tests

Collapse
 
pbeekums profile image
Beekey Cheung

The article was about the short term benefits of unit tests. The idea is that in some situations, it is faster to do initial development with unit tests than without.

For example: I recently wrote an email reply parser (splitting one email into many from the chain of replies quoted in it). This has dozens of test cases. The code for it is also very complex and has some messy regular expressions. I wasn't going to send an email every time I wanted to test things. I wrote some scripts with the email text in them. At this point, I realized I could convert those scripts into unit tests in less than 5 minutes. Running my script manually and maintaining those test scripts was a lot more cumbersome than unit tests.

This wasn't the long term. This was over the course of a few days. Those unit tests saved me hours of manual testing. This was a situation where if the schedule is too tight for unit tests, then the schedule is too tight to get the thing working at all.

Does that mean unit tests save you time when building basic CRUD apps? Not really. Those unit tests really are long term projects. But unit tests are almost always worth it with complex code.

Collapse
 
jamesrichmond24 profile image
James Richmond

I'm on your side - I'm also a big fan of unit testing.
I write unit tests whenever I can, but sometimes there is just not enough time..
About this part: "There’s also the benefit that a new developer in that code base will either not know how to properly test it or will use up a lot of another developer’s time in a knowledge transfer."
Don't you think it's a drawback? if a new developer needs to write unit tests and he doesn't know how to properly write them, he will waist both his and other developer's time..

Thread Thread
 
pbeekums profile image
Beekey Cheung

Ah, sorry. I wasn't clear there. My point was that if unit tests already exist, it helps a new developer a lot by serving as documentation on the test cases they need to think about.

Thread Thread
 
jamesrichmond24 profile image
James Richmond

No doubt about that!
What are the unit testing frameworks that you're familiar with?

Thread Thread
 
pbeekums profile image
Beekey Cheung

I'm a big fan of stock testing frameworks. Go and Python have decent ones.

I've worked with others, but one thing I really appreciate is simplicity. Granted, Go's testing framework is so bare bones it doesn't come with assertion functions, but that doesn't bother me that much.

I think complexity in set up or in trying to create the first test creates a lot of resistance to newcomers from building unit tests. Go and Python get you started in minutes. Frameworks tend to take a few hours at a minimum. They also have more random "gotchas" that result in lots of time on stack overflow.

Thread Thread
 
jamesrichmond24 profile image
James Richmond

I work with Typemock Isolator for C# - it's a very simple and user friendly tool, that allows you to perform unit testing by mocking almost anything you need.
It didn't take me a lot of time at all to understated how to work with it.
Have you heard about it?