RAG-Assert: Hybrid Retrieval-Augmented Assertion Generation for Automated Unit Testing

Test assertions are a key mechanism for validating program behavior in unit testing, and their quality determines the defect detection capability and engineering utility of automated tests. Existing assertion generation approaches fall into two main categories: deep learning-based methods, which are sensitive to training data scale and suffer from limited generalization, and retrieval-based methods, which rely on shallow lexical similarity and fail to capture deep code semantics. To address these limitations, this paper proposes Retrieval-Augmented Assertion Generation (RAG-Assert), a retrieval-augmented assertion generation method for automated unit testing. RAG-Assert constructs a hybrid retriever that combines token-level Jaccard similarity and CFG-derived basic-block semantic similarity to retrieve the most relevant historical assertion from the retrieval repository for a given focal test. The retrieved assertion is incorporated as external knowledge context during fine-tuning and generation of a pretrained code model. A beam-search decoding strategy is further adopted to select the reliable assertion from multiple candidates, reducing the probability of generating semantically inconsistent assertions. Experiments on the Methods2Test dataset demonstrate that RAG-Assert consistently outperforms five representative baseline methods across multiple metrics including Top-1 accuracy, Top-10 accuracy, and Bilingual Evaluation Understudy (BLEU) score. Evaluation on the Defects4J benchmark further confirms the practical defect detection capability of the proposed method. Ablation studies validate the complementary advantages of combining token-level similarity and CFG-derived basic-block semantic similarity in the hybrid retriever.

Authors

Publication Details

Journal
International Journal of Pattern Recognition and Artificial Intelligence
Published
2026-10-22
DOI
https://doi.org/10.1142/s0218001426590494
Primary Topic
Software Testing and Debugging Techniques
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

RAG-Assert: Hybrid Retrieval-Augmented Assertion Generation for Automated Unit Testing

Qiming Wu, Tiegang Zhang, Haibin Sui, Weibiao Chen et al.
International Journal of Pattern Recognition and Artificial Intelligence
Software Testing and Debugging Techniques
article

RAG-Assert: Hybrid Retrieval-Augmented Assertion Generation for Automated Unit Testing

Qiming Wu, Tiegang Zhang, Haibin Sui, Weibiao Chen, Chao Ma, Chengwen Ji
article en

Abstract

Test assertions are a key mechanism for validating program behavior in unit testing, and their quality determines the defect detection capability and engineering utility of automated tests. Existing assertion generation approaches fall into two main categories: deep learning-based methods, which are sensitive to training data scale and suffer from limited generalization, and retrieval-based methods, which rely on shallow lexical similarity and fail to capture deep code semantics. To address these limitations, this paper proposes Retrieval-Augmented Assertion Generation (RAG-Assert), a retrieval-augmented assertion generation method for automated unit testing. RAG-Assert constructs a hybrid retriever that combines token-level Jaccard similarity and CFG-derived basic-block semantic similarity to retrieve the most relevant historical assertion from the retrieval repository for a given focal test. The retrieved assertion is incorporated as external knowledge context during fine-tuning and generation of a pretrained code model. A beam-search decoding strategy is further adopted to select the reliable assertion from multiple candidates, reducing the probability of generating semantically inconsistent assertions. Experiments on the Methods2Test dataset demonstrate that RAG-Assert consistently outperforms five representative baseline methods across multiple metrics including Top-1 accuracy, Top-10 accuracy, and Bilingual Evaluation Understudy (BLEU) score. Evaluation on the Defects4J benchmark further confirms the practical defect detection capability of the proposed method. Ablation studies validate the complementary advantages of combining token-level similarity and CFG-derived basic-block semantic similarity in the hybrid retriever.

International Journal of Pattern Recognition and Artificial Intelligence
Openalex Percentile: Top 3%
Software Testing and Debugging Techniques
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon
RAG-Assert: Hybrid Retrieval-Augmented Assertion Generation for Automated Unit Testing — Qiming Wu, Tiegang Zhang, et al. · International Journal of Pattern Recognition and Artificial Intelligence (2026) | TGRS Research Map | TGRS