[Paper Review] Large Language Models are Few-shot Testers: Exploring LLM-based General Bug Reproduction
This paper proposes Libro, a framework that leverages Large Language Models (LLMs) to automatically generate test cases from natural language bug reports in Java projects. By post-processing LLM outputs and applying validation heuristics, Libro successfully reproduces bugs in 33.5% of Defects4J cases and suggests a valid reproducing test as the top result for 149 bugs, demonstrating strong potential for reducing developer effort in test creation.
Many automated test generation techniques have been developed to aid developers with writing tests. To facilitate full automation, most existing techniques aim to either increase coverage, or generate exploratory inputs. However, existing test generation techniques largely fall short of achieving more semantic objectives, such as generating tests to reproduce a given bug report. Reproducing bugs is nonetheless important, as our empirical study shows that the number of tests added in open source repositories due to issues was about 28% of the corresponding project test suite size. Meanwhile, due to the difficulties of transforming the expected program semantics in bug reports into test oracles, existing failure reproduction techniques tend to deal exclusively with program crashes, a small subset of all bug reports. To automate test generation from general bug reports, we propose LIBRO, a framework that uses Large Language Models (LLMs), which have been shown to be capable of performing code-related tasks. Since LLMs themselves cannot execute the target buggy code, we focus on post-processing steps that help us discern when LLMs are effective, and rank the produced tests according to their validity. Our evaluation of LIBRO shows that, on the widely studied Defects4J benchmark, LIBRO can generate failure reproducing test cases for 33% of all studied cases (251 out of 750), while suggesting a bug reproducing test in first place for 149 bugs. To mitigate data contamination, we also evaluate LIBRO against 31 bug reports submitted after the collection of the LLM training data terminated: LIBRO produces bug reproducing tests for 32% of the studied bug reports. Overall, our results show LIBRO has the potential to significantly enhance developer efficiency by automatically generating tests from bug reports.
Motivation & Objective
- To investigate the feasibility of using LLMs to generate test cases directly from natural language bug reports, a task largely unexplored in automated testing.
- To address the challenge of generating semantically meaningful tests for non-crash bugs, which existing techniques often overlook due to the oracle problem.
- To develop a framework that not only generates potential test cases but also ranks and validates them to ensure reliability and reduce developer cognitive load.
- To evaluate the method’s robustness against data contamination by testing on post-training bug reports not seen during LLM pretraining.
Proposed method
- Libro prompts the Codex LLM with a bug report and source code to generate candidate test cases in a few-shot prompting setup.
- It applies post-processing heuristics to filter and validate generated test outputs based on syntactic correctness, compilation success, and execution behavior.
- The framework ranks generated tests by assessing their likelihood of reproducing the reported failure using metrics such as compilation success, runtime exception, and test execution outcome.
- It uses a combination of static analysis and dynamic execution to verify whether a generated test reproduces the bug, distinguishing valid from invalid attempts.
- The system is evaluated on both the Defects4J benchmark and a newly collected real-world report-test dataset to assess generalization and robustness.
- To mitigate data leakage, the method evaluates on 31 post-training bug reports to ensure results are not due to memorization.
Experimental results
Research questions
- RQ1Can LLMs effectively generate test cases from natural language bug reports without relying on crash-based oracles?
- RQ2How accurately can a framework like Libro identify and rank the most promising test candidates among multiple LLM-generated outputs?
- RQ3To what extent does Libro generalize to real-world, post-training bug reports not present in the LLM’s training data?
- RQ4What are the key characteristics of bug reports and test cases that lead to successful reproduction by LLM-based generation?
Key findings
- Libro successfully reproduces a failure-inducing test case for 251 out of 750 (33.5%) Defects4J bugs, demonstrating strong performance on a widely used benchmark.
- For 149 of these bugs, Libro generates a valid, failure-reproducing test as its first suggestion, significantly reducing developer effort in test selection.
- In a separate evaluation on a newly collected real-world dataset of 31 post-training bug reports, Libro reproduces 32.2% of the bugs, showing generalization beyond the training data.
- The framework achieves 71.4% accuracy in correctly identifying which generated test actually reproduces the bug, indicating strong reliability in test ranking.
- The method performs poorly on bugs requiring external files or non-standard testing infrastructure, highlighting current limitations in handling complex test dependencies.
- Only three cases showed potential memorization of test code from reports, suggesting minimal data contamination in the results.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.