利用函数耦合自动生成测试用例,解决软件测试中难找验证结果的问题。
MR-Coupler: Automated Metamorphic Test Generation via Functional Coupling Analysis

- 通过分析代码中方法的函数耦合关系,自动生成测试用例。
- 在100个任务中90%以上生成有效用例,检测44%真实缺陷。
- 适合想落地自动化测试的开发者和研究者使用。
metamorphic testing(MT)是一种缓解软件测试中难以获得验证结果问题的主流技术。但其应用受限于有效metamorphic relations(MR)的构建难度,通常需要领域知识或难以获取的信息。本文提出MR-Coupler,一种利用源码中天然存在的函数耦合关系,自动构造MR并生成metamorphic test cases(MTCs)的新方法。该技术识别功能耦合的方法对,借助大语言模型生成候选测试用例,并通过测试扩增与变异分析进行验证。特别地,采用三种函数耦合特征避免方法对的昂贵枚举,设计新型验证机制减少误报。在100个手工编写MTCs和50个真实漏洞上的评估表明,MR-Coupler在超过90%的任务中生成有效MTCs,相比基线提升64.90%的有效生成率,误报率降低36.56%;生成的测试用例可检测44%的真实漏洞。结果表明,利用函数耦合可有效实现自动化MR构造,且MR-Coupler具备推动MT实际应用的潜力。工具与实验数据已公开,以支持后续研究。
原文摘要 · Abstract (English)
Metamorphic testing (MT) is a widely recognized technique for alleviating the oracle problem in software testing. However, its adoption is hindered by the difficulty of constructing effective metamorphic relations (MRs), which often require domain-specific or hard-to-obtain knowledge. In this work, we propose a novel approach that leverages the functional coupling between methods, which is readily available in source code, to automatically construct MRs and generate metamorphic test cases (MTCs). Our technique, MR-Coupler, identifies functionally coupled method pairs, employs large language models to generate candidate MTCs, and validates them through test amplification and mutation analysis. In particular, we leverage three functional coupling features to avoid expensive enumeration of possible method pairs, and a novel validation mechanism to reduce false alarms. Our evaluation of MR-Coupler on 100 human-written MTCs and 50 real-world bugs shows that it generates valid MTCs for over 90% of tasks, improves valid MTC generation by 64.90%, and reduces false alarms by 36.56% compared to baselines. Furthermore, the MTCs generated by MR-Coupler detect 44% of the real bugs. Our results highlight the effectiveness of leveraging functional coupling for automated MR construction and the potential of MR-Coupler to facilitate the adoption of MT in practice. We also released the tool and experimental data to support future research.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。