자동 디버깅을 위한 단위 테스트 생성 학습
Learning to Generate Unit Tests for Automated Debugging
February 3, 2025
저자: Archiki Prasad, Elias Stengel-Eskin, Justin Chih-Yao Chen, Zaid Khan, Mohit Bansal
cs.AI
초록
단위 테스트(Unit tests, UTs)는 코드의 정확성을 평가하고 동시에 대규모 언어 모델(LLM)에 피드백을 제공하여 결함이 있는 코드를 반복적으로 수정하는 데 중요한 역할을 합니다. 이는 자동화된 테스트 생성을 촉발합니다. 그러나, 우리는 결함이 있는 코드를 주면 오류를 드러내는 단위 테스트 입력을 생성하는 것과 골드 솔루션에 액세스하지 않고 단위 테스트 출력을 올바르게 예측하는 것 사이의 상충관계를 발견했습니다. 이 상충관계를 해결하기 위해 우리는 UTGen을 제안합니다. 이는 작업 설명과 후보 코드를 기반으로 오류를 드러내는 단위 테스트 입력과 그에 대한 올바른 예상 출력을 생성하는 방법을 LLM에 가르칩니다. 우리는 UTGen을 UTDebug에 통합하여 생성된 테스트를 사용하여 LLM이 효과적으로 디버깅하는 강력한 디버깅 파이프라인을 구축합니다. 모델이 생성한 테스트는 잘못된 출력으로부터 노이즈 신호를 제공할 수 있기 때문에, UTDebug은 (i) 테스트 시간 계산을 통해 UT 출력 예측을 개선하기 위해 UTGen을 확장하고, (ii) 오버피팅을 피하기 위해 생성된 여러 UT에 기반한 편집을 확인하고 되추적합니다. 우리는 UTGen이 오류를 드러내는 UT 입력과 올바른 UT 출력의 양존재를 측정하는 메트릭을 기반으로 UT 생성 기준선을 7.59% 능가한다는 것을 보여줍니다. UTDebug와 함께 사용할 때, UTGen의 단위 테스트로부터의 피드백은 HumanEvalFix의 Qwen-2.5 7B의 pass@1 정확도를 다른 LLM 기반 UT 생성 기준선 대비 3% 이상 및 MBPP+의 더 어려운 디버깅 분할에 대해 각각 12.35% 이상 향상시킵니다.
English
Unit tests (UTs) play an instrumental role in assessing code correctness as
well as providing feedback to a large language model (LLM) as it iteratively
debugs faulty code, motivating automated test generation. However, we uncover a
trade-off between generating unit test inputs that reveal errors when given a
faulty code and correctly predicting the unit test output without access to the
gold solution. To address this trade-off, we propose UTGen, which teaches LLMs
to generate unit test inputs that reveal errors along with their correct
expected outputs based on task descriptions and candidate code. We integrate
UTGen into UTDebug, a robust debugging pipeline that uses generated tests to
help LLMs debug effectively. Since model-generated tests can provide noisy
signals (e.g., from incorrectly predicted outputs), UTDebug (i) scales UTGen
via test-time compute to improve UT output prediction, and (ii) validates and
back-tracks edits based on multiple generated UTs to avoid overfitting. We show
that UTGen outperforms UT generation baselines by 7.59% based on a metric
measuring the presence of both error-revealing UT inputs and correct UT
outputs. When used with UTDebug, we find that feedback from UTGen's unit tests
improves pass@1 accuracy of Qwen-2.5 7B on HumanEvalFix and our own harder
debugging split of MBPP+ by over 3% and 12.35% (respectively) over other
LLM-based UT generation baselines.Summary
AI-Generated Summary