Retrieval-Augmented Test Generation: How Far Are We?
Jiho Shin, Nima Shiri Harzevili, Reem Aleithan, Hadi Hemmati, Song Wang

TL;DR
This paper explores the use of Retrieval-Augmented Generation (RAG) for generating unit tests for ML/DL APIs, analyzing different knowledge sources and models, and demonstrating improvements in test coverage and bug detection.
Contribution
It is the first comprehensive study applying RAG to unit test generation for ML/DL APIs, evaluating multiple knowledge sources and state-of-the-art LLMs.
Findings
RAG improves line coverage by 6.5% on average.
GitHub issues as knowledge source yield the best coverage improvements.
Generated tests helped detect 28 new bugs, with 24 reported to developers.
Abstract
Retrieval Augmented Generation (RAG) has advanced software engineering tasks but remains underexplored in unit test generation. To bridge this gap, we investigate the efficacy of RAG-based unit test generation for machine learning (ML/DL) APIs and analyze the impact of different knowledge sources on their effectiveness. We examine three domain-specific sources for RAG: (1) API documentation (official guidelines), (2) GitHub issues (developer-reported resolutions), and (3) StackOverflow Q&As (community-driven solutions). Our study focuses on five widely used Python-based ML/DL libraries, TensorFlow, PyTorch, Scikit-learn, Google JAX, and XGBoost, targeting the most-used APIs. We evaluate four state-of-the-art LLMs -- GPT-3.5-Turbo, GPT-4o, Mistral MoE 8x22B, and Llama 3.1 405B -- across three strategies: basic instruction prompting, Basic RAG, and API-level RAG. Quantitatively, we assess…
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
TopicsNatural Language Processing Techniques · Topic Modeling · Web Data Mining and Analysis
MethodsRefunds@Expedia|||How do I get a full refund from Expedia? · 15 Ways to Contact How can i speak to someone at Delta Airlines · Attention Is All You Need · WordPiece · Cosine Annealing · Linear Warmup With Linear Decay · {Dispute@FaQ-s}How to file a dispute with Expedia? · Linear Warmup With Cosine Annealing · Byte Pair Encoding · BERT
