Skip to content
Book Open access

Grounding AI Agents in Contracts: An Empirical Evaluation of Spec-Driven Test Generation

Aug 2026 · Proceedings of the 1st International Workshop on Specification-Driven Development Life Cycle · 0 citations · 46 references
Computer Science

TL;DR

It is shown that test suites generated by the spec-driven agent are superior to the baseline and human-authored tests in 77.8% and 56.7% of the cases, respectively, and demonstrated improvements on following best practices, readability, and edge-case coverage.

Abstract

LLM-based agents are increasingly used for coding tasks, where they have outperformed many classical approaches and scaled to repository-level tasks, such as test generation. However, when directly prompted to generate tests, these agents can fail to reason about the code and its underlying contracts, thereby missing edge cases and behavioral boundaries that affect test quality. To address this limitation, we propose Spec-Driven Test Generation, where we instruct an agent to first reason about – and explicitly document – code pre-conditions, post-conditions, and undefined behaviors. This intermediate semi-formal specification acts as a cognitive scaffold to guide subsequent test generation. Our evaluation on production bugs from Google shows that the spec-driven agent can deliver a 9.8 percentage points (p = 0.0352) improvement in bug detection rate and a 2.5 percentage point (p = 0.0034) improvement in branch coverage, compared to a traditional test generation agent baseline. Using LLM-as-a-Judge, we further show that test suites generated by the spec-driven agent are superior to the baseline and human-authored tests in 77.8% and 56.7% of the cases, respectively, and demonstrated improvements on following best practices, readability, and edge-case coverage.

Read PDF

Similar papers

Preprint Aug 2026

TDD-Agent: Test-Driven Reasoning for Code Generation

TDD-Agent is introduced, which operationalizes the test-driven development paradigm for code generation and improves not only code correctness but also the effectiveness of the generated tests, yielding higher pass rates, coverage, and mutation scores, suggesting that tests can serve as evolving reasoning artifacts rat...

Hong Yu, Ke-Fan Li, Jia-Kun Li et al. · 2 citations
Jul 2026

What Makes a Good Bug Report for an AI Agent?

It is found that a good bug report for an agent overlaps with, but is not identical to, a good report for a human: agents benefit most from concrete, executable, and well-localized information, whereas some qualities long emphasized for human readers, such as natural language steps to reproduce and readable description...

Lara Khatib, N. Mathews, M. Nagappan et al. · 2 citations · ⚡1
Preprint Aug 2026

Tangent: An Empirical Study of Testing Practices for LLM-Based Agent Applications

This paper constructs a large-scale dataset of agent applications, tools, and tests, and manually label 2,572 test methods from 240 modules, and derives a taxonomy of 23 testing patterns across test fixtures, data, objectives, and assertions, and characterize tests by level.

Rangeet Pan, Tyler Stennett, D. Sankar et al. · 1 citation
Review Jul 2026

ExplainBench: Evaluating Code Explanations from Agents

This work proposes ExplainBench, a benchmark to automatically evaluate explanations from coding agents, based on the intuition that informative explanations should enable an LLM to correctly answer questions, allowing quantitative comparison of explanation quality between agents.

Zhiyuan Pan, Sung-Min Kang, Imam Nur Bani Yusuf et al. · 0 citations
Jul 2026

Test Coverage Analysis of Agentic Pull Requests

Analysis of agent-generated PRs from the AIDev dataset studies how often agents include test changes and how well covered are code changes by existing and agent-written tests, finding error-handling constructs are the most consistently under-tested.

A. Dipongkor, Talank Baral, Wing Lam et al. · 0 citations

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.