Unit Test Case Generation with Transformers
Authors: Michele Tufano, Dawn Drain, Alexey Svyatkovskiy, Shao Kun Deng, Neel Sundaresan
Abstract
Automated Unit Test Case generation has been the focus of extensive literature within the research community. Existing approaches are usually guided by the test coverage criteria, generating synthetic test cases that are often difficult to read or understand for developers. In this paper we propose AthenaTest, an approach that aims at generating unit test cases by learning from real-world, developer-written test cases. Our approach relies on a state-of-the-art sequence-to-sequence transformer model which is able to write useful test cases for a given method under test (i.e., focal method). We also introduce methods2test - the largest publicly available supervised parallel corpus of unit test case methods and corresponding focal methods in Java, which comprises 630k test cases mined from 70k open-source repositories hosted on GitHub. We use this dataset to train a transformer model to translate focal methods into the corresponding test cases. We evaluate the ability of our model in generating test cases using natural language processing as well as code-specific criteria. First, we assess the quality of the translation compared to the target test case, then we analyze properties of the test case such as syntactic correctness and number and variety of testing APIs (e.g., asserts). We execute the test cases, collect test coverage information, and compare them with test cases generated by EvoSuite and GPT-3. Finally, we survey professional developers on their preference in terms of readability, understandability, and testing effectiveness of the generated test cases.
The papers around it, by date and closeness
Higher is closer to this paper; left is older. Lines join papers close to each other: groups of lines are sub-topics. Select a point to see why it is there. Back to the summary of this paper
Papers around this one
Ranked by how close their title and abstract are to this paper’s. Select some to read them together.
Closest papers
-
Transformer-Based Unit Test GenerationK. A. Rafique, Pooja J. Biradar, Christoph Grimm · 2025 · Conference on Algebraic Informatics · cited 1 time · Not summarized yet
Transformer-Based Unit Test Generation compares CodeT5, CodeBERT, and CodeGen for Python test generation, while this paper trains AthenaTest on Java focal-method/test pairs.
Abstract
Automated test case generation reduces the manual effort of software testing, particularly for dynamic languages like Python. This study compares three transformer-based models-CodeT5, CodeBERT, and CodeGen. While CodeBERT and CodeGen were expected to excel due to their focus on code understanding and generation, CodeT5, a code summarization model, outperformed both, achieving higher code coverage and superior semantic and syntactic fidelity. Using a limited yet diverse dataset of Python functions with natural language descriptions and unit tests, we evaluated models with NLP metrics (BLEU, ROUGE-L) and practical measures like code coverage. CodeGen struggled with coherence under data constr…
-
Reimagining Unit Test Generation With AI: A Journey From Evolutionary Models to TransformersSintayehu Zekarias Esubalew, Beakal Gizachew Assefa · 2025 · IEEE Access · cited 1 time · Not summarized yet
Reimagining Unit Test Generation With AI surveys AI-based unit test generation methods, including transformer approaches, with a focus on Java.
Abstract
The rapid evolution of software development necessitates efficient unit testing to ensure reliability, yet manual test case generation is labor-intensive and often inadequate for agile workflows. Despite advancements, a comprehensive review of AI-driven unit test case generation, particularly for Java, is lacking, motivating this study to address this gap. The paper examines AI algorithms for unit test case generation, focusing on Java-specific challenges like class hierarchies and dependency injection. We propose a novel taxonomy categorizing methods into traditional machine learning (e.g., genetic algorithms, SVMs), deep learning (e.g., RNNs, GNNs), and transformer-based approaches (e.g., …
-
Generating Accurate Assert Statements for Unit Test Cases using Pretrained TransformersMichele Tufano, Dawn Drain, Alexey Svyatkovskiy et al. · 2020 · International Conference/Workshop on Automation of Software Test · cited 144 times · Not summarized yet
Generating Accurate Assert Statements for Unit Test Cases using Pretrained Transformers generates assert statements, whereas this paper generates whole unit test cases from focal methods.
Abstract
Unit testing represents the foundational basis of the software testing pyramid, beneath integration and end-to-end testing. Automated software testing researchers have proposed a variety of techniques to assist developers in this time-consuming task. In this paper we present an approach to support developers in writing unit test cases by generating accurate and useful assert statements. Our approach is based on a state-of-the-art transformer model initially pretrained on an English textual corpus. This semantically rich model is then trained in a semi-supervised fashion on a large corpus of source code. Finally, we finetune this model on the task of generating assert statements for unit test…
-
From Fine-tuning to Output: An Empirical Investigation of Test Smells in Transformer-Based Test Code GenerationAhmed Aljohani, Hyunsook Do · 2024 · ACM Symposium on Applied Computing · cited 10 times · Not summarized yet
From Fine-tuning to Output studies test smells in transformer-generated test code, including AthenaTest, which this paper introduced.
Abstract
Researchers have recently leveraged transformer-based test code generation models to improve testing-related tasks (e.g., assert completion and test method generation). One such model, AthenaTest, has been recently introduced, and it has been well accepted by developers due to its ability to generate test cases similar to the ones written by developers. While the AthenaTest model provides adequate test coverage and improves test code readability, concerns remain regarding the quality of its generated test code, particularly the presence of test smells, which could degrade the test code's comprehension, readability, performance, and maintainability. In this paper, we investigated whether test…
-
A3Test: Assertion-Augmented Automated Test Case GenerationSaranya Alagarsamy, C. Tantithamthavorn, A. Aleti · 2023 · Information and Software Technology · cited 133 times · Not summarized yet
A3Test augments test generation with assertion knowledge and signature checks to address correctness limitations it identifies in AthenaTest.
Abstract
Test case generation is an important activity, yet a time-consuming and laborious task. Recently, AthenaTest -- a deep learning approach for generating unit test cases -- is proposed. However, AthenaTest can generate less than one-fifth of the test cases correctly, due to a lack of assertion knowledge and test signature verification. In this paper, we propose A3Test, a DL-based test case generation approach that is augmented by assertion knowledge with a mechanism to verify naming consistency and test signatures. A3Test leverages the domain adaptation principles where the goal is to adapt the existing knowledge from an assertion generation task to the test case generation task. We also intro…
-
Domain Adaptation for Code Model-Based Unit Test Case GenerationJiho Shin, S. Hashtroudi, H. Hemmati et al. · 2023 · International Symposium on Software Testing and Analysis · cited 41 times · Not summarized yet
Domain Adaptation for Code Model-Based Unit Test Case Generation fine-tunes CodeT5 on Methods2test and adapts it to project data, extending this paper's dataset-based task.
Abstract
Recently, deep learning-based test case generation approaches have been proposed to automate the generation of unit test cases. In this study, we leverage Transformer-based code models to generate unit tests with the help of Domain Adaptation (DA) at a project level. Specifically, we use CodeT5, a relatively small language model trained on source code data, and fine-tune it on the test generation task. Then, we apply domain adaptation to each target project data to learn project-specific knowledge (project-level DA). We use the Methods2test dataset to fine-tune CodeT5 for the test generation task and the Defects4j dataset for project-level domain adaptation and evaluation. We compare our app…
-
Exploring the Effectiveness of Large Language Models in Generating Unit TestsMohammed Latif Siddiq, Joanna C. S. Santos, Ridwanul Hasan Tanvir et al. · 2023 · Software Engineering · cited 138 times · AI summary available
Exploring the Effectiveness of Large Language Models in Generating Unit Tests evaluates prompted CodeGen, Codex, and GPT-3.5, citing this paper's transformer-based test-generation work.
Abstract
A code generation model generates code by taking a prompt from a code comment, existing code, or a combination of both. Although code generation models (e.g., GitHub Copilot) are increasingly being adopted in practice, it is unclear whether they can successfully be used for unit test generation without fine-tuning. To fill this gap, we investigated how well three generative models (CodeGen, Codex, and GPT-3.5) can generate test cases. We used two benchmarks (HumanEval and Evosuite SF110) to investigate the context generation's effect in the unit test generation process. We evaluated the models based on compilation rates, test correctness, coverage, and test smells. We found that the Codex mo…
-
A3Test: Assertion-Augmented Automated Test case generationSaranya Alagarsamy, Chakkrit Kla Tantithamthavorn, Aldeida Aleti · 2024 · Information and Software Technology · cited 96 times · Not summarized yet
A3Test adds assertion knowledge and test-signature verification to unit test generation, addressing shortcomings it reports in AthenaTest.
Abstract
Context: Test case generation is a critical yet challenging task in software development. Recently, AthenaTest – a Deep Learning (DL) approach for generating unit test cases has been proposed. However, our revisiting study reveals that AthenaTest can generate less than one-fifth of the test cases correctly, due to a lack of assertion knowledge and test signature verification. Objective: This paper introduces A3Test, a novel DL-based approach to the generation of test cases, enhanced with assertion knowledge and a mechanism to verify consistency of the name and signatures of the tests. A3Test aims to adapt domain knowledge from assertion generation to test case generation. Method: A3Test empl…
Prior work it builds on
-
An Empirical Investigation on the Readability of Manual and Generated Test CasesGiovanni Grano, Simone Scalabrino, H. Gall et al. · 2018 · IEEE International Conference on Program Comprehension · cited 82 times · Not summarized yet
An Empirical Investigation on the Readability of Manual and Generated Test Cases examines test readability, a quality dimension this paper evaluates with developers.
Abstract
Software testing is one of the most crucial tasks in the typical development process. Developers are usually required to write unit test cases for the code they implement. Since this is a time-consuming task, in last years many approaches and tools for automatic test case generation — such as EvoSuite — have been introduced. Nevertheless, developers have to maintain and evolve tests to sustain the changes in the source code; therefore, having readable test cases is important to ease such a process. However, it is still not clear whether developers make an effort in writing readable unit tests. Therefore, in this paper, we conduct an explorative study comparing the readability of manually wri…
-
On Learning Meaningful Assert Statements for Unit Test CasesCody Watson, Michele Tufano, Kevin Moran et al. · 2020 · International Conference on Software Engineering · cited 220 times · Not summarized yet
On Learning Meaningful Assert Statements for Unit Test Cases uses neural translation to generate meaningful assertions, a test component also examined in this paper.
Abstract
Software testing is an essential part of the software lifecycle and requires a substantial amount of time and effort. It has been estimated that software developers spend close to 50% of their time on testing the code they write. For these reasons, a long standing goal within the research community is to (partially) automate software testing. While several techniques and tools have been proposed to automatically generate test methods, recent work has criticized the quality and usefulness of the assert statements they generate. Therefore, we employ a Neural Machine Translation (NMT) based approach called Atlas (AuTomatic Learning of Assert Statements) to automatically generate meaningful asse…
-
Automatic test case generation: what if test code quality matters?Fabio Palomba, Annibale Panichella, A. Zaidman et al. · 2016 · International Symposium on Software Testing and Analysis · cited 70 times · Not summarized yet
Automatic test case generation: what if test code quality matters? addresses generated test quality, a concern this paper evaluates through readability and testing effectiveness.
-
Automated unit test generation for evolving softwareS. Shamshiri · 2015 · ESEC/SIGSOFT FSE · cited 35 times · Not summarized yet
Automated unit test generation for evolving software concerns automated unit testing, the broader problem this paper addresses with transformer-generated tests.
-
Exploring the Limits of Transfer Learning with a Unified Text-to-Text TransformerColin Raffel, Noam Shazeer, Adam Roberts et al. · 2019 · Machine Learning · cited 28,272 times · AI summary available
Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer studies transformer transfer learning, a modeling foundation used by this paper.
Abstract
Transfer learning, where a model is first pre-trained on a data-rich task before being fine-tuned on a downstream task, has emerged as a powerful technique in natural language processing (NLP). The effectiveness of transfer learning has given rise to a diversity of approaches, methodology, and practice. In this paper, we explore the landscape of transfer learning techniques for NLP by introducing a unified framework that converts all text-based language problems into a text-to-text format. Our systematic study compares pre-training objectives, architectures, unlabeled data sets, transfer approaches, and other factors on dozens of language understanding tasks. By combining the insights from o…
Papers that cite it
-
Evaluating and Improving ChatGPT for Unit Test GenerationZhi-Qiang Yuan, Ming-Wei Liu, Shiji Ding et al. · 2024 · Proc. ACM Softw. Eng. · cited 275 times · Not summarized yet
Evaluating and Improving ChatGPT for Unit Test Generation evaluates and improves LLM-generated unit tests, citing this paper's earlier approach.
Abstract
Unit testing plays an essential role in detecting bugs in functionally-discrete program units (e.g., methods). Manually writing high-quality unit tests is time-consuming and laborious. Although the traditional techniques are able to generate tests with reasonable coverage, they are shown to exhibit low readability and still cannot be directly adopted by developers in practice. Recent work has shown the large potential of large language models (LLMs) in unit test generation. By being pre-trained on a massive developer-written code corpus, the models are capable of generating more human-like and meaningful test code. In this work, we perform the first empirical study to evaluate the capability…
-
No More Manual Tests? Evaluating and Improving ChatGPT for Unit Test GenerationZhi-Qiang Yuan, Yiling Lou, Ming-Wei Liu et al. · 2023 · arXiv.org · preprint, not peer reviewed · cited 239 times · Not summarized yet
No More Manual Tests? Evaluating and Improving ChatGPT for Unit Test Generation assesses ChatGPT for unit test generation and cites this paper.
Abstract
Unit testing is essential in detecting bugs in functionally-discrete program units. Manually writing high-quality unit tests is time-consuming and laborious. Although traditional techniques can generate tests with reasonable coverage, they exhibit low readability and cannot be directly adopted by developers. Recent work has shown the large potential of large language models (LLMs) in unit test generation, which can generate more human-like and meaningful test code. ChatGPT, the latest LLM incorporating instruction tuning and reinforcement learning, has performed well in various domains. However, It remains unclear how effective ChatGPT is in unit test generation. In this work, we perform the…
-
TOGA: A Neural Method for Test Oracle GenerationElizabeth Dinella, Gabriel Ryan, T. Mytkowicz et al. · 2021 · International Conference on Software Engineering · cited 218 times · Not summarized yet
TOGA uses a transformer-based neural model to generate test oracles, applying a related model family to a different testing task.
Abstract
Testing is widely recognized as an important stage of the software development lifecycle. Effective software testing can provide benefits such as bug finding, preventing regressions, and documentation. In terms of documentation, unit tests express a unit's intended functionality, as conceived by the developer. A test oracle, typically expressed as an condition, documents the intended behavior of a unit under a given test prefix. Synthesizing a functional test oracle is a challenging problem, as it must capture the intended functionality rather than the implemented functionality. In this paper, we propose TOGA (a neural method for Test Oracle GenerAtion), a unified transformer-based neural ap…
-
An Empirical Study of Unit Test Generation with Large Language ModelsLin Yang, Chen Yang, Shutao Gao et al. · 2024 · Software Engineering · cited 169 times · AI summary available
An Empirical Study of Unit Test Generation with Large Language Models evaluates open-source LLMs and prompting strategies for unit tests, citing this paper.
Abstract
Unit testing is an essential activity in software development for verifying the correctness of software components. However, manually writing unit tests is challenging and time-consuming. The emergence of Large Language Models (LLMs) offers a new direction for automating unit test generation. Existing research primarily focuses on closed-source LLMs (e.g., ChatGPT and CodeX) with fixed prompting strategies, leaving the capabilities of advanced open-source LLMs with various prompting settings unexplored. Particularly, open-source LLMs offer advantages in data privacy protection and have demonstrated superior performance in some tasks. Moreover, effective prompting is crucial for maximizing LL…
-
An Empirical Evaluation of Using Large Language Models for Automated Unit Test GenerationMax Schäfer, Sarah Nadi, Aryaz Eghbali et al. · 2023 · IEEE Transactions on Software Engineering · cited 508 times · Not summarized yet
An Empirical Evaluation of Using Large Language Models for Automated Unit Test Generation studies prompt-based LLM testing without additional training and cites this paper.
Abstract
Unit tests play a key role in ensuring the correctness of software. However, manually creating unit tests is a laborious task, motivating the need for automation. Large Language Models (LLMs) have recently been applied to various aspects of software development, including their suggested use for automated generation of unit tests, but while requiring additional training or few-shot learning on examples of existing tests. This paper presents a large-scale empirical evaluation on the effectiveness of LLMs for automated unit test generation without requiring additional training or manual effort. Concretely, we consider an approach where the LLM is provided with prompts that include the signatur…
Go further
How are these papers found?
We compare the title and abstract of this paper with those of every paper summarized on this site, and with the papers Semantic Scholar recommends, those it cites and those citing it (for a much-cited paper, its most recent citations and, from OpenAlex, the most cited ones). Among the prior work and the follow-ups, the papers that use each other in depth, a method it uses and the much-cited follow-ups come a little higher. The levels (very close, close, related) come from the similarity of the texts, not from a judgment of quality; * marks a paper without an abstract, compared by its title. The sentence under a paper is written by an AI from the two abstracts: check it in the papers. A paper marked not relevant by three readers leaves the list.
Updated on 5 November 2026.