# Automated Support for Unit Test Generation: A Tutorial Book Chapter

arXiv: https://arxiv.org/abs/2110.13575 · HTML: https://mlsanity.com/paper/2110.13575/

## Key facts

- No citing papers in the map yet (data through 14 Oct 2026).
- Builds on 10 of its 34 references that are in the map.
- First posted on arXiv 26 Oct 2021.

## Builds on (most cited first, 10 of 10)

- [Evaluating Large Language Models Trained on Code](https://mlsanity.com/paper/2107.03374/) (2021)
- [Automated Unit Test Generation for Python](https://mlsanity.com/paper/2007.14049/) (2020)
- [Test Set Diameter: Quantifying the Diversity of Sets of Test Cases](https://mlsanity.com/paper/1506.03482/) (2015)
- [Understanding Flaky Tests: The Developer's Perspective](https://mlsanity.com/paper/1907.01466/) (2019)
- [Using Machine Learning to Generate Test Oracles: A Systematic Literature Review](https://mlsanity.com/paper/2107.00906/) (2021)
- [Uncertainty-Driven Black-Box Test Data Generation](https://mlsanity.com/paper/1608.03181/) (2016)
- [Boundary Value Exploration for Software Analysis](https://mlsanity.com/paper/2001.06652/) (2020)
- [Learning How to Search: Generating Effective Test Cases Through Adaptive Fitness Function Selection](https://mlsanity.com/paper/2102.04822/) (2021)
- [Visualizing test diversity to support test optimisation](https://mlsanity.com/paper/1807.05593/) (2018)
- [Towards Automated Boundary Value Testing with Program Derivatives and Search](https://mlsanity.com/paper/1905.11198/) (2019)

## Abstract (arXiv)

Unit testing is a stage of testing where the smallest segment of code that can be tested in isolation from the rest of the system - often a class - is tested. Unit tests are typically written as executable code, often in a format provided by a unit testing framework such as pytest for Python. Creating unit tests is a time and effort-intensive process with many repetitive, manual elements. To illustrate how AI can support unit testing, this chapter introduces the concept of search-based unit test generation. This technique frames the selection of test input as an optimization problem - we seek a set of test cases that meet some measurable goal of a tester - and unleashes powerful metaheuristic search algorithms to identify the best possible test cases within a restricted timeframe. This chapter introduces two algorithms that can generate pytest-formatted unit tests, tuned towards coverage of source code statements. The chapter concludes by discussing more advanced concepts and gives pointers to further reading for how artificial intelligence can support developers and testers when unit testing software.
