Why should we write unit tests? I guess most developers have thought about this already at some stage in their career, and Unit testing is is important. But it’s also hard. That’s why in this article, I argue how you can make unit testing easier by keeping keep your test suite in a manageable size at any time. In fact, you should start today to reduce the number of unit tests that you have for your projects (and thank me tomorrow in the comments section below).

Why do you need a small test suite?

Usually, people think that the more test cases they have, the more certain they can be that their code works. In practice, it’s rather this way: the more test cases you have, the more time you have to spend on maintaining them. Because in the end, maintaining unit tests is where the actual effort of unit testing lies. If your unit tests are not up to date however, they have no value at all. In the end, keeping your unit tests up to date is a whole bunch of work (I’ve written more on this here: The Pain in Unit Testing – and How to Cure it). After every change in the software, you need to check which tests fail, why they fail (are they outdated, or did they find a bug?) and potentially fix them. Obviously, the smaller the size of your test suite, the easier it is to maintain them. On the other side, even if you have a lot of test cases, this doesn’t necessarily mean that you have tested the most important parts of your software. Most developers fancy to test one particular part of their code extensively (usually the first classes that they have written, because they were still motivated to do unit tests at that time). But So make sure that you keep only the unit tests that are actually crucial for the quality of your software in your test suite, and get rid of the rest.

How to do it?

To reduce your test suite today, and keep it in a manageable size in the future, you simply need to follow these three steps (the third one is actually a bonus to help you boost your efficiency): 

1. Get rid of bad unit tests. First, you need to identify the unit tests that you actually don’t need, because they cause more harm than they actually help you. I’ve written a detailed instruction on how to do this here: 5 Bulletpoints how to spot Bad Unit Tests

2. Define only the most efficient unit tests. If you create new unit tests, you should make sure that you focus on those who provide the most value to the quality of your software. For defining unit tests, there are 2 methods that you can use here, which are described in detail here:  2 methods that help you save 60 % of your effort in Unit Testing.

3. Let AI help you! With so-called meta-heuristic search algorithms, you can even automate the reduction of your unit tests. Genetic Algorithms such as NSGA-II have for example shown to be quite effective here: Search Algorithms for Regression Test Case Prioritization. The basic idea is to create a trade-off between the number of unit tests in your test suite, and the effectiveness of your test suite (in terms of code coverage or mutation score). The meta-heuristic search algorithm can effectively give you a set of unit tests that optimize this trade-off.

So, start reducing you unit tests today – and let me know how it went, in the comments section below!

Prioritize vector created by pch.vector – www.freepik.com

Leave a Comment

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.

Privacy Settings saved!
Privacy Settings

When you visit any web site, it may store or retrieve information on your browser, mostly in the form of cookies. Control your personal Cookie Services here.

GetResponse, Google Analytics

We use LinkedIn Insight for marketing purposes. You can disable these cookies.

We use Google Analytics for marketing purposes. You can disable these cookies.
  • __utmz
  • __utma
  • _ga
  • _gat

We use GetResponse for marketing purposes. This service cannot be disabled, otherwise the website functions will be limited.

Decline all Services
Accept all Services
Get Free Access Now to
9 eBooks!
All about Automated Software Testing
Proven experts
Learn to save up to 75% of your test efforts
Get Free Access Now!
Get Access Now! & Save 50%
Personal Trainer FREE Nutrition Custom Workout App
Get Access Now!
eBook Download
Enter your details to get your free ebook!
All about Automated Software Testing
Download Free Ebook
Lorem ipsum dolor sit amet, consectetur adipiscing