Evaluating and Mitigating the Misguidance Effect of Buggy Code in LLM-Generated Unit Tests

Junda Zhao, Shurui Zhou, Eldan Cohen
7/24/2026
cs.SEcs.AIcs.LG

No confident code implementation found for this paper.

Abstract

While Large Language Models (LLMs) show great promise for automating unit test generation, recent studies suggest that the quality of generated tests can be negatively impacted when models are prompted with buggy code. This paper presents a new metric to quantitatively measure the "misguidance effect," a phenomenon where buggy code steers LLMs toward generating tests that validate its erroneous behavior rather than expose it.

Show full abstract

Our analysis reveals that prompting LLMs with buggy code has a severe, twofold impact: it significantly increases "misguided tests" that assert incorrect behavior while simultaneously suppressing the generation of effective, bug-finding tests. We further corroborate this effect from a model-internal perspective, showing that buggy code skews LLMs' preference toward tests that assert the same erroneous behavior. To counter this, we introduce and validate a specification-based unit test generation paradigm that replaces the code under test in the prompt with an LLM-generated specification docstring. Our results show that this paradigm effectively reduces misguided tests while substantially increasing effective tests, improves multi-round, feedback-driven test generation pipelines, and remains applicable to both buggy and bug-free code. Overall, these results suggest that specification-based prompting is a promising strategy for mitigating misguidance from buggy code in LLM-generated unit tests.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{zhao2026evaluating,
  title  = {Evaluating and Mitigating the Misguidance Effect of Buggy Code in LLM-Generated Unit Tests},
  author = {Junda Zhao and Shurui Zhou and Eldan Cohen},
  year   = {2026},
  eprint = {2607.22883},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2607.22883v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2607.22883.svg)](https://codeofpaper.com/paper/2607.22883)

Discussion