mlsanityData to 7 Oct 2026

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

arXiv 2608.17177 ↗First posted 17 Aug 2026cs.SEcited by 0

On the map: LLM agents and tool use → Software engineering coding agents

Abstract (arXiv)

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.

Key facts. No citing papers in the map yet (data through 7 Oct 2026). Placed in Software engineering coding agents, one of 16 directions in LLM agents and tool use. Builds on 16 of its 46 references that are in the map. First posted on arXiv 17 Aug 2026.

Builds on

16 of 46 references.

Closest ancestors · 4

Same direction, newest first

  1. 2026SpecBench: Evaluating Specification-Level Reasoning for Software Engineering LLM Agents28 May
  2. 2026Dynamic Cogeneration of Bug Reproduction Test in Agentic Program Repair27 Jan
  3. 2025TestForge: Feedback-Driven, Agentic Test Suite Generation18 Mar
  4. 2024SWT-Bench: Testing and Validating Real-World Bug-Fixes with Code Agents18 Jun

Other references · 12

  1. 2024CRUXEval: A Benchmark for Code Reasoning, Understanding and Executioncited by 294
  2. 2020Unit Test Case Generation with Transformers and Focal Contextcited by 118
  3. 2023Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions?cited by 53
  4. 2023Effective Test Generation Using Pre-trained Large Language Models and Mutation Testingcited by 51
  5. 2025Code to Think, Think to Code: A Survey on Code-Enhanced Reasoning and Reasoning-Driven Code Intelligence in LLMscited by 47
  6. 2020On Learning Meaningful Assert Statements for Unit Test Casescited by 42
  7. 2024CoverUp: Effective High Coverage Test Generation for Pythoncited by 36
  8. 2023Learning Deep Semantics for Test Completioncited by 31
  9. 2023CAT-LM: Training Language Models on Aligned Code And Testscited by 28
  10. 2025Autoformalization in the Wild: Assessing LLMs on Real-World Mathematical Definitionscited by 20
  11. 2025HoarePrompt: Structural Reasoning About Program Correctness in Natural Languagecited by 7
  12. 2026RubberDuckBench: A Benchmark for AI Coding Assistantscited by 3

Built on by

Not cited yet.

Similar, not cited

Close in wording, no citation either way

  1. 2026Rethinking the Value of Agent-Generated Tests for LLM-Based Software Engineering Agents
  2. 2026Automated structural testing of LLM-based agents: methods, framework, and case studies
  3. 2026Complex Agents, Shallow Tests: Demystifying and Enhancing Test Adequacy of Agent Harness in the Wild
  4. 2026SpecPath: Testing Coding Agents Across Contract-Equivalent Specification Histories
  5. 2026Beyond Test Presence: Assessing the Quality and Robustness of Agent-Generated Tests in Open-Source Projects
  6. 2026TDD-Agent: Test-Driven Reasoning for Code Generation
  7. 2026Verus-SpecGym: An Agentic Environment for Evaluating Specification Autoformalization
  8. 2026Test-Driven AI Agent Definition (TDAD): Compiling Tool-Using Agents from Behavioral Specifications