TL;DR
SWT-Bench is a new benchmark designed to evaluate how well AI "Code Agents" can transform natural language bug reports into executable, reproducing test cases. The study reveals that agents designed for code repair are surprisingly adept at testing, and leveraging these AI-generated tests can double the precision of automated bug-fixing tools by acting as a rigorous validation filter.
What Problem Does This Paper Address?
While Large Language Models (LLMs) have shown remarkable progress in writing code, the equally critical task of software testing remains under-explored. Specifically, "issue reproduction"—the process of taking a vague user bug report and writing a test case that proves the bug exists—is a tedious chore that human developers often dislike.
Existing benchmarks for automated testing are often outdated, limited in size, or focused on simple "interview-style" problems rather than complex, real-world codebases. Without robust automated testing, we cannot fully trust AI-generated code fixes. The authors address this by creating a framework to evaluate whether AI agents can formalize informal user issues into "Fail-to-Pass" (F→P) tests: tests that fail on the buggy version of a program but pass once the bug is fixed.
Methods
The researchers took a two-pronged approach: building a better benchmark and adapting state-of-the-art agents for the task.
- SWT-Bench Construction: They repurposed the popular SWE-Bench (a code repair benchmark) by focusing on the "golden" tests and patches provided by human developers. A generated test is considered successful if it reproduces the specific issue described.
- Fault-Tolerant Diff Format: Standard "unified diff" formats (like those used by Git) are notoriously difficult for LLMs because they require precise line numbers. The authors introduced a custom, more robust format that allows agents to rewrite entire functions or classes, significantly reducing formatting errors.
- Agent Adaptation: They adapted existing top-tier Code Agents—SWE-Agent, Aider, and AutoCodeRover—by simply modifying their system prompts. Instead of telling the agent to "fix the bug," they instructed it to "create a unit test that reproduces the issue."
- SWE-Agent+: They introduced a variant that explicitly instructs the agent to execute its generated tests and iterate based on the output before final submission.
Datasets
The primary contribution is the SWT-Bench dataset:
- Scope: 1,983 real-world task instances drawn from 12 popular open-source Python repositories (e.g., Django, Scikit-learn, SymPy).
- SWT-Bench-Lite: A smaller subset of 276 instances used for more cost-effective evaluation.
- Composition: Each instance includes a natural language issue description, the codebase at the time of the report, a "golden" human-written patch, and reference tests.
Key Insights and Ideas
- Agents > Specialized Tools: Interestingly, general-purpose Code Agents designed for repair outperformed specialized test-generation tools like LIBRO. This suggests that the ability to navigate and "understand" a repository is more important for testing than specific test-generation heuristics.
- Testing vs. Fixing are Different Skills: The researchers found that an agent's ability to fix a bug doesn't perfectly correlate with its ability to write a test for it on a per-sample basis. Some bugs are easy to fix but hard to reproduce with a test, and vice versa.
- The Power of Filtering: One of the most practical findings is that generated tests can serve as a "gatekeeper." By only accepting code fixes that pass the agent's own self-generated reproduction tests, the precision of the SWE-Agent tool doubled (from ~20% to 47.8%).
- Context is King: Providing the agent with the specific file that needs to be changed (even without the fix itself) nearly doubled the success rate. This highlights that "retrieval"—finding where the bug lives—is a major bottleneck.
Key Results
The evaluation on SWT-Bench-Lite showed significant performance jumps using the authors' methods:
- Success Rate ($S$): The best-performing agent, SWE-Agent+, achieved a success rate of 18.5%, significantly higher than simple zero-shot prompting (3.6%).
- Diff Format Impact: Moving from standard diffs to the authors' custom
ZeroShotPlusformat tripled the success rate of GPT-4 (from 3.6% to 9.4%). - Change Coverage: Successful tests generated by agents achieved high coverage of the "golden patch" code (averaging 69.4% for SWE-Agent+), indicating that the tests were hitting the relevant parts of the logic.
Limitations and Future Work
- Language Constraint: The benchmark is currently limited to Python. Generalizing these findings to languages like Java or C++ remains to be seen.
- Data Contamination: Since the benchmark uses historical GitHub data, there is a risk that the LLMs saw some of these issues during their initial training. While the authors tested for this, a "rolling" benchmark with brand-new issues would be a more robust future solution.
- Scope of Testing: The current work focuses on reproducing known bugs. Future work could expand this to edge-case detection (finding bugs the user hasn't reported yet) or improving global code coverage.
Summary updated