一句话:提出 rTED,用类型约束分析与反射验证引导 LLM 生成单元测试,精准检测 Python 类型错误并降低误报。
Python 类型错误常导致运行时失败,现有静态分析工具虽无需执行即可检测,但误报率高;单元测试生成虽有高覆盖率潜力,却缺乏针对性引导,难以生成暴露 bug 的测试。为此,本文提出 rTED:一种类型感知的测试生成技术,将逐步类型约束分析与反射式验证相结合,引导大语言模型生成测试并抑制误报。作者在 BugsInPy 与 TypeBugs 两个基准上评估,rTED 比四种最先进技术多检测出 22~29 个类型错误,精确率提升 173.9%~245.9%;在六个真实开源 Python 项目中发现 12 个此前未知的类型错误。
Type errors in Python often lead to runtime failures, posing significant challenges to software reliability and developer productivity. Existing static analysis tools aim to detect such errors without execution but frequently suffer from high false positive rates. Recently, unit test generation techniques offer great promise in achieving high test coverage, but they often struggle to produce bug-revealing tests without tailored guidance. To address these limitations, we present rTED, a novel type-aware test generation technique for automatically detecting Python type errors. Specifically, rTED combines step-by-step type constraint analysis with reflective validation to guide the test generation process and effectively suppress false positives. We evaluated rTED on two widely-used benchmarks, BugsInPy and TypeBugs. Experimental results show that rTED can detect 22 ∼ 29 more benchmarked type errors than four state-of-the-art techniques. rTED is also capable of producing fewer false positives, achieving an improvement of 173.9%∼245.9% in precision. Furthermore, we applied rTED to six real-world open-source Python projects, and successfully discovered 12 previously unknown type errors, demonstrating rTED’s practical value.
DOI 原文 ·
@inproceedings{paperbot9270,
title = {Reflective Unit Test Generation for Precise Type Error Detection with Large Language Models},
author = {Chen Yang and Ziqi Wang and Yanjie Jiang and Lin Yang and Yuteng Zheng and Jianyi Zhou and Junjie Chen},
booktitle = {ASE},
year = {2025},
doi = {10.1109/ase63991.2025.00233}
}