A Paper Published by the ACM in October 2026 Says Buggy Code Steers Language Models Toward Unit Tests That Validate the Bug Rather Than Expose It

A paper in the Proceedings of the ACM on Software Engineering, in its ISSTA issue of October 2026, finds that prompting language models with buggy code increases tests that assert the incorrect behavior and suppresses tests that would detect it, and proposes prompting with a specification instead.

Unit testing, a paper published by the ACM in October 2026 says, verifies "that individual components behave as expected." The paper, in the ISSTA issue of the Proceedings of the ACM on Software Engineering, asks what happens when a large language model writes those tests from code that already has a bug in it. Its authors call the result the misguidance effect: "a phenomenon where buggy code steers LLMs toward generating tests that validate its erroneous behavior rather than expose it." The paper is read here in its authors' own copy, which carries its ACM reference. Parts of it follow, not the whole, and the models it tested are not named here.

Illustration

Tests That Agree With the Bug

The paper says earlier studies of AI-written unit tests mostly gave the models bug-free code, and often relied on correctness and coverage, measures "which do not directly reflect the bug detection effectiveness of the generated tests." That design, it says, "fails to mirror real-world scenarios where the code under test is often buggy."

"Buggy code has a severe, twofold negative impact on LLM-generated tests. It misleads models into producing misguided tests that validate the bug and simultaneously suppresses effective tests that would detect it." The authors say they corroborate this from inside the models, showing that "the model's preference is skewed toward tests that assert the buggy behavior in the prompt." Their correlation analysis, they add, suggests "that models with stronger code comprehension capabilities can be more susceptible to misguidance."

A test written from the code can learn the code's mistake. It then passes, and the pass says nothing about the bug.

A Specification in Place of the Code

The paper's remedy is to take the code out of the prompt. Its method "replaces the code under test in the prompt with an LLM-generated specification docstring." On buggy code, the authors report, this significantly reduced misguided tests while substantially increasing the count of effective tests, and it worked better than earlier methods that only added a specification beside the buggy code.

They draw a further lesson from inspecting the specifications by hand. "These findings show that merely removing buggy implementation details is not enough; recovering the correct behavior is essential for generating effective tests." On bug-free code, they report, the method "does not significantly increase compilation-failure or false-alarm rates compared to the code input baseline, and it maintains a comparable level of test coverage."

What the Study Covers

The authors set out their own limits. The study relies on one benchmark, which they call a common choice in prior work, and uses 318 methods across all 17 of its projects, tested on 11 language models. They say the benchmark "may not fully capture two real-world scenarios": proprietary or highly domain-specific systems, where models may lack the knowledge to infer the intended behavior, and deeply stateful or dependency-rich code, where a method-level docstring may omit important class, state or dependency information. They also name data contamination as a threat, since the benchmark's own tests may have been in the models' training data, and say their method's gains suggest "that the LLMs are not simply recalling memorized tests."

The tests pass or fail against what they are told the code should do. Told the wrong thing, they can stay green over the bug.