LLM-based Unit Test Generation via Property Retrieval
Zhe Zhang, Xingyu Liu, Yuanzhang Lin, Xiang Gao, Hailong Sun, Yuan, Yuan

TL;DR
This paper introduces Property-Based Retrieval Augmentation for LLMs to improve unit test generation by considering task-specific context and code structure, leading to more correct, complete, and maintainable tests.
Contribution
It proposes a novel property retrieval mechanism that enhances LLM-based test generation by incorporating task-specific context and code relationships, surpassing traditional retrieval methods.
Findings
APT outperforms existing tools in correctness, completeness, and maintainability.
The property retrieval approach effectively leverages code relationships for better test generation.
The method demonstrates consistent improvements across 12 open-source projects.
Abstract
Automated unit test generation has been widely studied, with Large Language Models (LLMs) recently showing significant potential. Moreover, in the context of unit test generation, these tools prioritize high code coverage, often at the expense of practical usability, correctness, and maintainability. In response, we propose Property-Based Retrieval Augmentation, a novel mechanism that extends LLM-based Retrieval-Augmented Generation (RAG) beyond basic vector, text similarity, and graph-based methods. Our approach considers task-specific context and introduces a tailored property retrieval mechanism. Specifically, in the unit test generation task, we account for the unique structure of unit tests by dividing the test generation process into Given, When, and Then phases. When generating tests for a focal method, we not only retrieve general context for the code under test but also…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSoftware Testing and Debugging Techniques · VLSI and Analog Circuit Testing · Real-time simulation and control systems
