断言
计算机科学
背景(考古学)
水准点(测量)
人工智能
相似性(几何)
源代码
语义相似性
单元测试
机器学习
编码(集合论)
雅卡索引
语义学(计算机科学)
自然语言处理
钥匙(锁)
解码方法
数据挖掘
比例(比率)
实施
试验数据
测试用例
情报检索
质量(理念)
编码(内存)
作者
Chao Ma,Tiegang Zhang,Chengwen Ji,Haibin Sui,Qiming Wu,Weibiao Chen
标识
DOI:10.1142/s0218001426590494
摘要
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.
科研通智能强力驱动
Strongly Powered by AbleSci AI