Why Should Software Testers Understand Unit Testing?

Getting Started — Published December 22, 2021

Learn why unit testing isn’t only for developers, the importance of unit testing to software testers and quality engineers, and how you can improve your skills by building better unit tests.

The responsibility for product quality frequently falls on software testers. Yet, software testers are often divorced or even excluded from conversations around the cheapest and easiest way to inject quality into the product and the entire software development lifecycle, right from the beginning: unit testing. In this article, we’ll explore why it’s important for software testers to be able to speak clearly about unit tests and how this can help deliver better quality.

Why Unit Tests Are Important

Unit tests form the solid base of the testing pyramid. They are the cheapest kinds of tests to run, and can be run frequently throughout the deployment pipeline. Unit tests allow us to find errors the soonest, and to fix them before they bubble up in other, more expensive kinds of testing like functional or UI tests, which take much longer to complete and run than unit tests.

Unit Testing Frameworks

Most developers know how to write unit tests in the language in which they develop, and most languages have several libraries to choose from, depending on the type and complexity of testing. For example, Python has pytest, pyunit, unittest(inspired by Java’s JUnit), Nose2, and hypothesis (for property tests, a non-example based type of unit test). These are just some of the choices available, and every language has a number of possible unit testing frameworks to choose from.

You don’t need to know everything about a unit testing library, or even how to write unit tests, to get value from understanding the basics of the unit testing framework. A lot of value can be gained from knowing what framework is being used, and what kinds of assertions can be made within the framework. Also, does the framework support table tests or property-style tests? Understanding what is supported can help you better understand what aspects of your test design might be best handled in the unit-testing phase. 

Unit Testing Is the Developers Job

Yes, developers typically write unit tests. However, they are largely responsible for writing these tests to ensure that the code works – most developer tests are likely to cover happy-path and obvious negative cases. They may not think to write tests for edge or corner cases, as they are working to meet deadlines for code delivery. This is where software testers with unit test knowledge can help to make the unit tests more robust, and perhaps decrease testing that might otherwise be done at integration or functional levels.

The first step, if you are unfamiliar with the code, is to request a walkthrough of the unit tests. Understanding what developers have done and what they are testing will help you to make recommendations about what other tests might be included. Remember, adding tests here is the cheapest and fastest place to do it, especially if there are tests you want run quickly on every code change that a developer makes. 

If you are familiar with the codebase and version control systems, then you can also look for the unit tests in the code. These are often stored in a test directory, and typically named so it is easy to identify what is being tested. Quality teams can be coached to review unit tests, and compare those with their test plans. Once coached, teams can make recommendations to developers to improve unit tests and make test suites more robust. Some team members may even expand their skills by adding tests and making pull requests/merge requests for unit tests. There are many ways to participate in making unit tests more effective, involving writing no code or writing a lot of code; it’s up to you to decide what most benefits you and your team. 

But What if There Are No Unit Tests?

If you are responsible for software quality and you discover that your team or company is not doing unit testing, this can be both painful, but also a great opportunity for growth. The first step in having the conversations around developing unit tests can revolve around the efficiency, efficacy, and speed of unit tests. The next step is building awareness and fluency about quality and testing as a part of development, which is a difficult task to tackle alone, and it may not work without buy-in from key people. However, if you can get understanding and buy-in on the importance of building testing and testability into the product starting with unit-tests as the foundation, further discussions about code quality can be opened up.

Better Quality is the Goal

At the end of every day, every member of the team should be responsible for quality. However, that responsibility rests with different people in different organizations, and often with the person who has the word “quality” in their title is the person who is ultimately held responsible in the end. If you are responsible for quality, understanding the basics of how unit tests work in your code base will help you to have better discussions with developers about how to improve software quality in the fastest, cheapest way possible – directly from the code.

Are you ready?

Get started Schedule a demo