Unit testing plays a critical role in ensuring software quality, especially in agile development.
Post by Sep 16, 2024 7:30:00 AM · 3 min read

Enhancing Software Quality Through Unit Testing

Unit testing is critical to software quality, especially in agile development. AI tools can help overcome the challenges of unit testing legacy systems.

TABLE OF CONTENTS

Defining Unit Testing

One of my first disagreements with my QA team at Ultimate Software was about the definition of unit testing. Many QA team members used the term when testing a small system section. In most cases, they meant story or feature testing. They executed the tests to verify that a specific story or feature was working as expected.

Current Definitions of Unit Testing

I tried to find out where the source of this confusion comes from. I checked some of the most famous QA books, and the definitions are similar. For example, Boris Beizer, in his “Software Testing Techniques” book, defines a unit as the smallest piece of software that can be independently tested (i.e., compiled or assembled, loaded, and tested). Usually the work of one programmer consisting of a few hundred lines of source code.

Today, no one will consider a few hundred lines of code a single unit. That is too big. Beizer was specific enough to indicate that unit testing is the work of programmers, for the most part. What kind of testing did my QA team do? Well, Louise Tamres does an excellent job of breaking down the levels in her book “Introducing Software Testing.” It is a question of scope. Here is her breakdown and definitions:

  • Unit level testing concerns the testing of the smallest compilation unit of some application. The goal of unit testing is to demonstrate that each individual unit functions as intended prior to integrating it with other units. The tester typically invokes the unit and enters data via a test driver that sends the test execution information to the unit-under-test.
  • Integration level testing consists of combining the individual units and ensuring that they function together correctly.
  • System level testing applies to the entire application as a whole. This is often how the end user views of the system. The tester typically interacts with the application by entering data the same way as would the end user.

Tamres' definition assumes you cannot access a unit through the user interface (UI). My QA team did all their “unit testing” through the UI. They were testing at the system level, no matter what they called it.

I always wonder if we have three levels of testing. The line between integration and system testing is blurry, but that is a subject for another blog post.

Agile and Unit Testing

Our understanding of unit testing underwent a significant transformation with the emergence of agile software development. Test-driven development (TDD), a practice within extreme programming (XP), revolutionized the concept of writing small isolated tests to verify functions or methods of the code. Writing the unit tests before writing the actual code was a game-changer, inspiring a new approach to software development. The “Red-Green-Refactor” TDD cycle, which involves writing a failing test (Red), writing the minimum code to pass the test (Green), and then refactoring the code to improve its design (Refactor), changed how software engineers think about writing code and set a new standard in the industry. The following diagram illustrates the process:

TDD became the way to implement quadrant 1 of the Marick Test Matrix: TDD includes write a failing test, make the test pass, and refactor.

TDD became the way to implement Quadrant 1 of Brian Marick’s testing matrix.

The Marick Test Matrix helps us consider quality holistically across four testing Quadrants.

TDD has become the standard practice for implementing a technology-facing supporting programming suite of unit tests. Agile also brought an explosion of unit testing frameworks. Kent Beck, one of the creators of XP, created one for Java called JUnit. Today, the most popular programming languages have at least one unit testing framework to support implementing TDD.

The publication of the agile testing pyramid established the importance of unit testing within agile software development.

The test pyramid established the importance of unit testing.

The agile testing pyramid calls for most testing to happen at the unit level. Other models have challenged this recommendation. For example, the trophy model recommends more integration tests than unit tests:

The Trophy model recommends more integration tests than unit tests.

Still, unit testing has become an essential part of software development projects. Agile engineering practices like TDD, BDD, and CI/CD are less common in software development. One reason for this dichotomy is the existence of legacy software. Implementing these practices can be challenging, especially in legacy systems. It often requires significant refactoring and a shift in mindset. Understanding these challenges can help you prepare for the realities of modern software development.

Stay tuned for the conclusion of this post about unit testing challenges coming on 9/23/24!

About the Author

Rafael E Santos is Testaify's COO. He's committed to a vision for Testaify: Delivering Continuous Comprehensive Testing through Testaify's AI-first testing platform.Testaify founder and COO Rafael E. Santos is a Stevie Award winner whose decades-long career includes strategic technology and product leadership roles. Rafael's goal for Testaify is to deliver comprehensive testing through Testaify's AI-first platform, which will change testing forever. Before Testaify, Rafael held executive positions at organizations like Ultimate Software and Trimble eBuilder.

Take the Next Step

Join the waitlist to be among the first to know when you can bring Testaify into your testing process.