SWT-Bench: Testing and Validating Real-World Bug-Fixes with Code Agents

Niels Mündler, Mark Niklas Müller, Jingxuan He, Martin T. Vechev

TL;DR

This paper introduces SWT-BENCH, a new benchmark for automatically generating unit tests that reproduce real-world software bugs. They demonstrate that LLM-based "Code Agents," originally designed for code repair, are surprisingly effective at this task, even outperforming specialized test generation methods. Crucially, these generated tests can then be used to significantly improve the precision of automated code fixes.

What Problem Does This Paper Address?

Developing and maintaining high-quality software relies heavily on rigorous testing. While automated test generation is a promising area, especially with the rise of Large Language Models (LLMs), it has been relatively underexplored compared to code generation itself. Existing work often focuses on simpler coding challenges or doesn't specifically address the critical task of reproducing real-world bugs reported in issue trackers. This gap hinders both improving software quality and making automated code repair tools more effective. The authors aim to bridge this gap by investigating how LLM-based Code Agents can generate tests that accurately reflect and reproduce reported issues.

Methods

The core of this work is the introduction of SWT-BENCH, a novel benchmark designed for test generation focused on issue reproduction. This benchmark is built upon existing code repair datasets, leveraging real-world GitHub issues, corresponding bug fixes, and a set of "golden" reference tests.

A key methodological contribution is the adaptation of LLM-based Code Agents for test generation. These agents, typically designed for code repair, are repurposed by adjusting their instructions to focus on creating tests that reproduce issues. The authors also propose a custom diff format that is more robust and easier for LLMs to generate compared to the standard unified diff format, particularly for test generation tasks which often involve adding new functions.

For evaluation, they use two primary metrics:

  • Success Rate (S): The proportion of generated tests that successfully reproduce the issue (fail before the fix, pass after).
  • Change Coverage (AC): The extent to which the generated tests cover the lines of code modified by the golden patch.

Datasets

The primary dataset introduced is SWT-BENCH. It's a novel benchmark derived from popular GitHub repositories, containing over 1900 task instances. Each instance includes:

  • A real-world GitHub issue description.
  • A "golden" code patch that fixes the issue.
  • A set of "golden" reference tests.

SWT-BENCH is related to SWE-BENCH (a benchmark for code repair) but specifically tailored for test generation. The authors also created a smaller subset, SWT-BENCH-LITE, for more efficient evaluation.

Key Insights and Ideas

  • Code Agents Excel at Test Generation: Surprisingly, Code Agents, even those designed for code repair, outperform specialized test generation methods on SWT-BENCH. This suggests that the underlying capabilities of these agents are highly transferable.
  • Test Generation as a Structured Task: While similar to code generation, test generation is more structured, allowing for more granular analysis of model performance through metrics like issue reproduction rate and coverage.
  • Generated Tests as a Filter for Code Fixes: The most impactful insight is that generated tests can act as a powerful filter for proposed code fixes. By using tests that fail before a fix and pass after, the precision of automated code repair systems can be significantly improved.
  • Issue Description Length Matters: Longer issue descriptions generally lead to better test generation performance, likely due to more available context. However, excessively long descriptions can become noisy.
  • Code Repair vs. Test Generation are Distinct: The overlap between solved instances for code repair and test generation is small, indicating these are distinct tasks with different difficulty levels.

Key Results

  • SWT-BENCH: Contains 2,294 task instances initially, reduced to 1,983 after filtering for reliability. Issue descriptions average 318 words, and repositories are complex with over 1,500 files and 300,000 lines of code.
  • Code Agent Performance: SWE-AGENT, a Code Agent, achieved a success rate (S) of 15.9% (and 18.5% with SWE-AGENT+ which checks its own tests), outperforming LIBRO (14.1%) and other methods.
  • Test Filtering: Using generated tests as a filter for proposed code fixes doubled the precision of SWE-AGENT.
  • Coverage: Successful instances showed significantly higher change coverage (ACS), indicating a correlation between test quality and coverage.
  • LLM Impact: The choice of LLM significantly impacts performance, with more capable models like GPT-4 and Claude 3.5 Sonnet showing better results.

Limitations and Future Work

  • Python-Centric: The current benchmark is limited to Python, potentially limiting generalizability to other languages.
  • Repository Representation: The dataset is based on popular GitHub repositories, which might not represent all software development practices.
  • Issue Scope: The dataset focuses on bug reproduction issues coverable by adding test cases, not necessarily edge case detection or global coverage increase.
  • Data Contamination: Issues in SWT-BENCH were created before the knowledge cutoff of some LLMs, posing a risk of data contamination. The authors suggest a rolling version of the benchmark to address this.
  • Future Work: Addressing limitations like Python-specificity, exploring more complex issue types, and developing better monitoring for common LLM errors in test generation are suggested.

Summary updated

BibTeX
@inproceedings{mundler2024swt,
  author = {Niels Mündler and Mark Niklas Müller and Jingxuan He and Martin T. Vechev},
  title = {{SWT-Bench: Testing and Validating Real-World Bug-Fixes with Code Agents}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=9Y8zUO11EQ},
}
Figure