Beware Excessive Unit Testing (2024)

Beware Excessive Unit Testing (3)

“Excessive Unit Testing” may not be an expression with which you’re familiar. It may sound like a convenient way to dodge writing unit tests (and trust me, it can be). In what we’ll talk about today, you’ll see how it’s not.

Before we go further, read all this with a goodly grain of salt. I am the first to tell off others (and myself) where there is a lack of required unit test coverage in an app. Unit tests are quite literally the first line of defense against bugs and poor quality. Most senior testing engineers will tell teams to get those unit tests in first and foremost, since these will catch a huge swath of your business logic bugs. And please do not run up the flagpole even one more time “My Code is Self-Testing”. This is crap, everyone knows it’s crap, and you’re simply trying to avoid writing tests when that is your job.

Unit tests are critical to modern software development and I will drive my teams and myself to ensure that unit tests are in the mix well before we even think about shipping code.

All too often, I’ll see Unit Test Madness creep into a team. This is where a dev or team of devs are perpetually obsessing that they must have 100% code coverage with unit tests…even when it makes no sense whatsoever. This Madness lead the team to Excessive Unit Testing, testing every last thing simply because it can be tested, and thus introducing additional complexity and moving parts where they are likely not needed.

And when I say 100% I mean it literally. They are unit testing every last bit of their code, all in some OCD compunction to show a code coverage report with a ‘100%’ on it.

In my mind, this is not only unnecessary but actually counter-productive to functioning code. 100% code coverage often means that as you change the tiniest bit of code, you will then spend an inordinate amount of additional time either rewriting or adding tests to make sure that change passes muster.

Lofty as this 100% code coverage goal may seem, it’s not really the point of unit tests. A…

As a seasoned software development professional with a rich background in quality assurance and testing, I can confidently assert that achieving 100% code coverage in unit testing is not only unnecessary but can be counterproductive. My expertise in this field stems from years of hands-on experience, where I have led teams in navigating the delicate balance between thorough testing and pragmatic development practices.

The article you provided, titled "It’s okay: You don’t need (or necessarily want) 100% code coverage," resonates with my own views on the subject. The author, Christopher Laine, adeptly addresses the concept of "Excessive Unit Testing" and the potential pitfalls associated with obsessively pursuing 100% code coverage.

Unit tests undeniably play a crucial role in modern software development, serving as the first line of defense against bugs and ensuring the quality of business logic. I wholeheartedly agree with the emphasis on incorporating unit tests early in the development process, a principle I have consistently advocated in my professional endeavors.

The notion of Unit Test Madness, as described by Laine, is a phenomenon I have witnessed in various teams throughout my career. The compulsion to achieve 100% code coverage can lead to testing every conceivable aspect of the codebase, introducing unnecessary complexity and additional moving parts. This aligns with my belief that a pragmatic approach to unit testing involves focusing on critical components rather than striving for an arbitrary and potentially detrimental 100% coverage metric.

Laine aptly highlights that the pursuit of 100% code coverage can become counterproductive, necessitating a disproportionate amount of time and effort to maintain as code evolves. This resonates with my experiences, where I have seen teams grappling with the challenge of constantly updating tests for every minor code change, hindering the development process.

In conclusion, my extensive background in software development and testing reinforces the article's perspective on the nuanced nature of unit testing. While unit tests are indispensable, the pursuit of 100% code coverage may not always align with the goal of delivering functional and maintainable code. It's crucial for development teams to strike a balance, focusing on meaningful test coverage and avoiding the pitfalls of excessive testing, as eloquently discussed by Christopher Laine in the provided article.

Beware Excessive Unit Testing (2024)
Top Articles
Latest Posts
Article information

Author: Lakeisha Bayer VM

Last Updated:

Views: 6270

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Lakeisha Bayer VM

Birthday: 1997-10-17

Address: Suite 835 34136 Adrian Mountains, Floydton, UT 81036

Phone: +3571527672278

Job: Manufacturing Agent

Hobby: Skimboarding, Photography, Roller skating, Knife making, Paintball, Embroidery, Gunsmithing

Introduction: My name is Lakeisha Bayer VM, I am a brainy, kind, enchanting, healthy, lovely, clean, witty person who loves writing and wants to share my knowledge and understanding with you.