loading...
Cover image for What are the benefits of writing automated testing?

What are the benefits of writing automated testing?

sdiamante13 profile image Steven Diamante ・1 min read

TLDR; I am giving a presentation on unit testing and TDD. I would like to know your opinions and experiences with automated testing.

I practice test driven development(TDD) every day at my job. I am a part of an extreme programming (XP) team in a 70 year old company. Other teams outside of our portfolio practice scrum and lack the testing reflex that we all have. A colleague and I are giving a presentation next month to our Java Community of Practice on unit testing. We will talk about its benefits and why developers should write tests. We will also talk about the benefits that writing tests first can have on your code quality. I know the benefits I gain from them, but I would like to hear from this community. If you have never written unit tests, then I would especially like to hear from you. What would you like to know about unit tests? If you dislike testing, what is it that you dislike? Feel free to share any opinions you have on the topic. Thanks in advance!

Posted on by:

sdiamante13 profile

Steven Diamante

@sdiamante13

Currently working on React and Java (Spring Boot) applications. Continuous learner and teacher!

Discussion

markdown guide
 

I think all the points I would mention (i.e., emergent design driven by tests, reducing waste through automation, reducing errors through automation, probably higher quality code) have been mentioned, apart from one:

  • Quick, positive feedback loops for the developer through Red -> Green (-> Refactor).

TDD is the fuel for me as a developer. It keeps my confidence high and lets me know when I start to head into risky territory when the cycles become long and/or Red -> Red -> Red -> Red -> Red -> Green -> Red, etc.

 

That's one of my favorite benefits! Thanks for contributing!

 

Do I have your permission to use this quote and your profile picture in my presentation?

 

No problems Steven - I hope it goes well.

 

Your unit tests are only ever going to be as useful as the person writing them, and the underlying code being tested in the first place.

They are not a silver bullet or a quality guarantee in your software.

Now, to discuss what I personally feel is the most valuable aspect of automated testing (specifically in the case of unit testing): test-driven-design.

This is a fairly radical restructuring of how you write code, by forcing you to write in a style that prioritizes understanding your execution as a series of inputs and outputs.

It encourages better software design by enforcing SOLID principles, with a heavy focus on SRP (single responsibility principle).

Writing software in this way naturally makes your solutions more resilient, with the added benefit of having automated tests to reinforce that.

 

Do I have your permission to use this quote and your profile picture/info (excluding email) in my presentation?

 
 

I totally agree! I am a huge advocate for test driven design as well. Thanks for your input!

 

I'm going at this from the angle as a software tester, so my opinion might differ slightly. :)

Whenever we deploy a system or the whole chain, we do sanity checks manually to make sure our core components are not affected by the release. If they are, rollback and cry. It consumes a lot of time and we have testers that have to be at the ready at 3am or something for these tests...

However, when there are automated tests in place (which some of our systems have), we can use the CI/CD pipelines to trigger the sanity checks. No need for human interaction, and also a lower risk of human error.

The same goes for regression tests, which can be used in even more situations. Regression tests (closest to the unit test, but from a functional pov) can be run at any moment, after any change. So, whenever you're merging branches, you can always run the regression tests. Does everything still works like it's supposed to! Awesome! Do we have failed tests? Rollback and cry again (and of course analyse where that little bug is at).

I can keep going like this, but these are some of my main arguments when it comes to automated testing.

Oh, and one last argument: when you're unit testing your code, you reduce the chances of that one hecc of an annoying tester being at your desk time and time again. ;)

 

Do I have your permission to use this quote and your profile picture/info in my presentation?

 

Of course! Feel free to use it. ^^

 

Thanks for the different perspective, Rose! Rollback and cry was cracking me up 😂 I'm going to use that from now on!

 

Hi Steven.

I started a discussion some years ago about problems with "real world TDD". Through that, I gained some interesting insights, why some people don't do (or even like) TDD in their daily work.

Some of the points are:

  • Tooling for some languages is not great
  • Managers and Architects telling devs that they don't need tests
  • Some people even stated that TDD does not exist outside of "simple 100 LOC examples"

Maybe you can use (and disprove 😄) some of that in your presentation.

 

It makes use of that computers are really good at: doing the same thing in exactly the same way with high precision and speed, and it will not get bored, lose interest or attention.
Humans are not able to do this. They are slow and inconsistent. Then they get tired, they get slower and more inconsistent.

So while the computer can continuously run tests to verify the proper working of software, the humans can focus on the things computers are not good at: solving problems and improving previous solutions.

 

Yeah that's a great point! I don't think about that aspect enough. Thanks!

 

I was lazy about unit testing because there's not an official framework for C and I thought I had to write a test for every component in my project.

You can do unit testing without a framework. Regular functions calling and checking on what you need to test, will do the job. You don't need to test everything, this is particularly true working with legacy code. You just need to modify your program so you can test a major feature without depending on a host, a peripheral or a user input. This is a good way to understand the code, and to see if that new code you just inserted don't break anything. Also this is a good way to start your tests base if you don't have one. New features and reported bugs may need you to go deeper in the tests, but only then you will write tests to verify your solution, your tests base will grow over time.

If you have a good tests base, then you can do refactoring in the safest possible way. Also a good tests base is the best documentation your code could have.

 

What are the benefits of writing automated testing?

As I just commented in Ben's "come back to it later" post, not killing astronauts with buggy calculations which could turn rockets into missiles.