一句话:用大语言模型分析规约自动增强测试预言,在 OpenJDK 中发现 45 个已被确认或修复的未知缺陷。
现有测试预言往往不完整,难以检测实现偏离规约的缺陷,而既有技术依赖粗粒度失败信号或大量人工投入。本文提出规约驱动的 JavaOracle,用 LLM 系统化增强测试预言:先分析规约推导测试未覆盖的预言,并以根因引导的修复流程保证用例有效;再以多智能体辩论区分真实规约违背与 LLM 幻觉导致的断言失败;最后自动最小化用例并生成缺陷报告。在 OpenJDK Java SE API 的 3961 个用例上,JavaOracle 优于 Fuzz4All、ChatAssert 与 Randoop,累计发现 45 个已被确认或修复的未知缺陷;流水线平均每次运行仅 6 份报告,精度 88.9%,增强用例执行通过率 79.1%。
Software testing critically depends on test oracles, yet existing test oracles are often incomplete and insufficient for detecting bugs where implementations deviate from their specifications. Meanwhile, despite advances in test oracle construction, existing techniques typically rely on coarse-grained failure signals or require substantial manual effort, and thus remain inadequate for detecting specification-violation bugs. To address these limitations, we propose JavaOracle, a specification-driven approach that leverages large language models (LLMs) to reason over specifications and systematically enhance test oracles. Specifically, JavaOracle consists of three stages. First, it leverages LLMs to analyze specifications and derive additional test oracles that are not covered by existing tests, while integrating a root-cause-guided repair workflow to ensure that the enhanced test cases are syntactically and semantically valid. Second, it designs a multi-agent debate workflow to distinguish previously unknown specification-violation bugs from assertion failures caused by LLM hallucinations, thereby mitigating the impact of hallucinations. Third, unlike existing approaches that stop at bug detection, JavaOracle further automates test case minimization and bug report generation, producing submission-ready reports without manual effort. We evaluate JavaOracle on 3,961 test cases for Java SE API from the OpenJDK. Experimental results on the latest OpenJDK standard library show that JavaOracle substantially outperforms state-of-the-art baselines, including Fuzz4All, ChatAssert, and Randoop. Cumulatively, JavaOracle discovers 45 previously unknown bugs, which have already been confirmed/fixed by developers, with many persisting since their initial implementation. In an entire pipeline running, JavaOracle reduces execution failures to an average of 6 reports per run, achieving 88.9% precision. In contrast, baseline approaches required exhaustive manual inspection to identify only 0, 3, and 2 real bugs, respectively. Further analysis shows that test cases enhanced by JavaOracle achieve high validity, with an execution pass rate of 79.1%, compared to 35.4%, 92.2% (55.5% test cases unchanged), and 77.6% for the baselines. Ablation studies further demonstrate the effectiveness of JavaOracle components, while the automated pipeline significantly reduces manual analysis effort.