Unit Testing

Unit Testing thumbnail

What is unit testing?


In computer programming, unit testing is a software testing method by which individual units of source code are tested for performance.


Unit testing is like a health inspector at a restaurant.

A health inspector is going to take a checklist and review each individual item. Rather than just experiencing the restaurant and assessing its cleanliness, the inspector will individually test each component of the health inspection to determine the overall score of the restaurant.

The inspector will individually score items, such as how clean the grills are or if there is any food that has already expired. Each individual score will help influence the overall assessment, informing the inspector of the general performance of the restaurant.

By testing each component individually, the inspector can more accurately identify if there are any issues and if so, what those issues are and where specifically the restaurant needs to improve.

In other words:

Unit testing is the process of testing individual pieces of code to ensure that the base components of a software project are working properly.

Why is unit testing important?

It's one thing to know what unit testing means, but that is worthless if you don't know why you should know what staff augmentation is in the first place. Let's break down the importance of this tech term based on two high level categories. We'll walk through an explanation as well as provide a score, 1-10, that shows you how much you should care about unit testing.

Pre-Product: 1/10

The first will be if you do not have a product yet. This means that you don't have a physical product. Maybe you're in the ideation phase, or maybe you're almost ready to start development. Whichever it is, we'll get into why unit testing is important and why you should or shouldn't care about it if you do not have a product.

If you don't have a product, there is nothing for you to test, so nothing for you to worry about here!

Live Product: 6/10

The second category is if you do have a live product. Maybe you just launched your business or maybe it's been live for years and you're continuing to improve its quality. Regardless of the scenario, if your product is live, unit testing carries a different weight.

Similar to integration testing, the importance of this process if you do have a product depends on where you are at in your product lifecycle. If you are pushing out an MVP, then you likely care less about the quality of testing than if you have live users. So, while this term and quality assurance process is important, first talk to your development team to determine its value.

Examples of unit testing

So you know whais, by definition. You know if you should care about it or not depending on your situation as a business/company/product. To dig in deeper, we will walk through some examples so we can make sure you really have a solid grasp on unit testing.

Unit testing is when specific parts or components of the software are being tested. You are breaking down the program into units, and testing them independently. It's important to know that unit testing is NOT the same as QA testing or end user testing. Unit testing is typically the first type of testing that is conducted. Let's break down some common formats of unit testing as well as determine what the pros and cons of following this form of code testing looks like.

Examples of Unit Testing:

The purpose of unit testing is to test the 'correctness' of an individual piece of code. As the first step of any form of QA testing, there are three main techniques for approaching this process: black box, white box, grey box.

Black Box Unit Testing

Black box unit testing is when you look to test the functional components of the user interface, input values and output values.

White Box Unit Testing

White box unit testing is when you look to test the functional behavior of a component of code. You perform this process by providing an input, reviewing the process, and determining if the output of the function is correct.

Grey Box Unit Testing

The grey box unit testing method is centered around test cases, test methods, and test functions. Your purpose here is to analyze code performance for each module.

Pros of Unit Testing:

Unit testing is an important part of the QA process. Let's walk through some reasons why unit testing would be seen as a pro for your QA process:

  1. Your code is more reliable since you've tested for edge cases.
  2. Unit tests make it easier to catch bugs.If your scripts are running tests on each new unit, it is less time consuming to identify the bug and consequently debug it. Read up on bugs and bug testing here!
  3. Maintaining and changing code is easier when you have written new code. Since unit tests are running successfully for the existing code, we can more quickly identify specific areas that are causing issues.

Cons of Unit Testing:

While unit testing is important and provides you with a roadmap for quality, it does have some cons that are important to take note of:

  1. It is time consuming as writing individual tests is not a simple task.
  2. You cannot identify every bug through unit testing.
  3. It doesn't guarantee quality. Even if the individual units are passing, if the tests weren't written in a way that encompasses all major units of your code, it won't guarantee your entire codebase is solid.

Key Takeaways:

  1. Unit testing is the process of testing individual pieces of code to ensure that the base components of a software project are working properly.
  2. There are three techniques of unit testing: black box, white box, and grey box.
  3. Unit testing is the foundation and often first step of quality assurance, pointing to the pros of unit testing.
  4. Unit testing can be time intensive and doesn't guarantee quality, making it a con if you're looking to move very quick.
  5. If you don't have a product, unit testing is nothing to concern yourself with.
  6. If you do have a product, you should chat with your development team to determine if unit testing is part of your QA process.
Not seeing a term? 🤔