Otter: Generating Tests from Issues to Validate SWE Patches

Toufique Ahmed, Jatin Ganhotra, Rangeet Pan, Avraham Shinnar, Saurabh Sinha, Martin Hirzel

Abstract

Automated software engineering (SWE) agents often lack reliable mechanisms to verify their proposed code fixes. We introduce Otter, an LLM-based system that generates reproduction tests directly from natural language issue descriptions. Otter employs a three-stage pipeline: localization of relevant code, self-reflective action planning, and test generation with automated code repair. To rigorously evaluate this task, we present TDD-Bench-Verified, a benchmark of 449 real-world Python issues. Our experiments demonstrate that Otter++ achieves state-of-the-art performance, successfully generating fail-to-pass tests for 37.0% of issues using GPT-4o, significantly outperforming existing baselines while remaining cost-effective.

1. Introduction

In modern software development, bug reports often lack reproduction scripts, forcing developers and AI agents to guess the efficacy of their fixes. While automated test generation for existing code is well-studied, generating tests from natural language descriptions—a "test-first" approach—remains a significant challenge. This paper addresses this gap by proposing Otter, a system designed to support Test-Driven Development (TDD) for both humans and automated agents.

2. The Otter Framework

Otter mimics a human developer's workflow through a modular pipeline designed to minimize hallucinations and maximize context relevance:

  • Localizer: Identifies relevant test files and focal functions using a two-step LLM process and a rule-based "hallucination replacer" to ensure file path accuracy.
  • Self-Reflective Action Planner: Instead of direct code generation, Otter formulates a plan involving "read," "write," or "modify" actions. It iteratively validates and improves this plan (up to five turns) to ensure it references valid codebase entities.
  • Test Generator: Executes the finalized plan. It includes an automated import-fixing step using static analysis (Flake8) to resolve missing dependencies.
The Otter pipeline architecture, featuring localization, self-reflective planning, and test generation stages.

We also introduce Otter++, an ensemble variant that utilizes heterogeneous prompting—running the generator with five distinct prompt configurations—to improve the robustness of test generation across diverse bug types.

3. TDD-Bench-Verified Dataset

To evaluate Otter, we created TDD-Bench-Verified, derived from the SWE-bench Verified dataset. We filtered 500 instances to ensure the "golden" tests exhibit true "fail-to-pass" behavior (failing on the bug, passing on the fix) and provide substantial code coverage. The final benchmark consists of 449 instances across 12 major Python repositories, including Django, Scikit-learn, and Matplotlib.

4. Results and Discussion

Otter demonstrates superior performance compared to existing tools. Using GPT-4o, Otter generates successful reproduction tests for 31.4% of issues, while the ensemble Otter++ reaches 37.0%. This significantly outperforms the previous state-of-the-art, SWE-Agent+, which achieved only 19.2%.

Performance comparison of Otter and Otter++ against zero-shot baselines across different LLMs.

Key insights from our evaluation include:

  • Planning Efficacy: Ablation studies showed that removing the action planner led to a performance decrease of 14% to 36%, highlighting the importance of structured reasoning before coding.
  • High Fidelity: Successful tests achieved over 93% code coverage, nearly identical to human-written tests.
  • Cost Efficiency: Otter is highly economical, costing approximately $0.06 to $0.09 per issue, making it a practical "gatekeeper" for validating agent-generated patches.

5. Conclusion

Otter bridges the gap between natural language bug reports and executable tests. While currently limited to Python and single-file test generation, it provides a powerful framework for automated software validation. Future work will focus on expanding language support and integrating Otter into the iterative loops of SWE agents to enable real-time self-correction.

Summary updated

BibTeX
@inproceedings{ahmed2025otter,
  author = {Toufique Ahmed and Jatin Ganhotra and Rangeet Pan and Avraham Shinnar and Saurabh Sinha and Martin Hirzel},
  title = {{Otter: Generating Tests from Issues to Validate SWE Patches}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=b0jYs6JOZu},
}
Figure