一句话:以基于性质的测试补充单元测试来评估 LLM 生成代码,揭示被 pass@k 掩盖的正确性缺口。
大语言模型在自动代码生成上表现可观,但保证正确性仍是难题。传统单元测试只检验功能正确性,难以捕捉更深层的逻辑约束。本文提出以基于性质的测试(PBT)作为补充评估策略,在 MBPP 与 HumanEval 基准上评估 StarCoder 与 CodeLlama 生成的代码,并从提示中抽取正确性性质。结果显示:pass@k 指标显示中等成功率,但 PBT 暴露出更多正确性缺口——30–32% 的生成解仅部分满足正确性性质,18–23% 完全失败;性质抽取本身也不完善,9–13% 的约束缺失。这表明仅依赖单元测试的评估会因遗漏基本逻辑错误而高估生成代码的正确性;将单元测试与 PBT 结合可给出更全面的代码正确性评估。
Large Language Models (LLMs) have shown promise in automated code generation, but ensuring correctness remains a significant challenge. Traditional unit testing evaluates functional correctness but often fails to capture deeper logical constraints. We apply Property-Based Testing (PBT) as an alternative evaluation strategy to StarCoder and CodeLlama on MBPP and HumanEval. Our results reveal that while pass@k evaluation shows moderate success, PBT exposes additional correctness gaps. A significant portion of generated solutions only partially adhere to correctness properties (30–32%), while 18–23% fail outright. Property extraction is also imperfect, with 9–13% of constraints missing. These findings highlight that unit test-based evaluations may overestimate solution correctness by not capturing fundamental logical errors. Our study demonstrates that combining unit testing with PBT can offer a more comprehensive assessment of generated code correctness, revealing limitations that traditional verification approaches miss.