Apprendimento per Generare Test Unitari per il Debugging Automatico
Learning to Generate Unit Tests for Automated Debugging
February 3, 2025
Autori: Archiki Prasad, Elias Stengel-Eskin, Justin Chih-Yao Chen, Zaid Khan, Mohit Bansal
cs.AI
Abstract
I test unitari (UT) svolgono un ruolo fondamentale nell'valutare la correttezza del codice e nel fornire un feedback a un grande modello di linguaggio (LLM) mentre corregge iterativamente il codice difettoso, motivando la generazione automatica di test. Tuttavia, scopriamo un compromesso tra la generazione di input di test unitari che rivelano errori quando viene fornito un codice difettoso e la previsione corretta dell'output del test unitario senza accesso alla soluzione corretta. Per affrontare questo compromesso, proponiamo UTGen, che insegna agli LLM a generare input di test unitari che rivelano errori insieme ai relativi output attesi corretti basati sulle descrizioni del compito e sul codice candidato. Integriamo UTGen in UTDebug, un robusto pipeline di debug che utilizza i test generati per aiutare gli LLM a debuggare in modo efficace. Poiché i test generati dal modello possono fornire segnali rumorosi (ad esempio, dagli output predetti in modo errato), UTDebug (i) scala UTGen tramite calcolo al momento del test per migliorare la previsione dell'output di UT, e (ii) convalida e fa marcia indietro sulle modifiche basate su più test UT generati per evitare l'overfitting. Dimostriamo che UTGen supera i baselines di generazione di UT del 7,59% basandoci su una metrica che misura la presenza sia degli input di UT che rivelano errori sia degli output di UT corretti. Quando usato con UTDebug, scopriamo che il feedback dai test unitari di UTGen migliora la precisione pass@1 di Qwen-2.5 7B su HumanEvalFix e sulla nostra suddivisione più difficile di debugging di MBPP+ di oltre il 3% e il 12,35% (rispettivamente) rispetto ad altri baselines di generazione di UT basati su LLM.
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