CodeScene study: Code health weakly predicts LLM test generation quality
Maintainable code yields better AI-generated tests—and cuts token usage across 3 languages.
A new study from CodeScene researchers—Freya Wirdemann, Markus Borg, Nadim Hagatulah, and Adam Tornhill—investigates how code maintainability affects LLM-generated test quality. The paper, accepted at IEEE SCAM 2026, applies CodeScene's CodeHealth (CH) metric to source code in Python, Java, and C++. The team then generated unit tests using LLM coding agents and evaluated them with traditional coverage metrics and mutation testing, providing a rigorous measure beyond simple line coverage.
The results offer a clear signal for engineering teams: CH shows a weak but consistent positive relationship with test effectiveness. In other words, the more maintainable the source code, the better the LLM-generated tests perform. More striking is the token efficiency finding—code with higher CH scores consistently correlated with lower input-token counts across all three languages, when measured with common industrial tokenizers. This suggests that investing in code health not only improves test quality but also reduces the computational cost of LLM-based development.
These findings reinforce the growing body of evidence that maintainable code is a prerequisite for effective AI-assisted software engineering. For practitioners, this means refactoring legacy or poorly structured code before applying AI testing tools could yield measurably better results. For organizations adopting AI coding agents, the study highlights code health as a lever to optimize both quality and cost. The authors plan to explore whether the relationship holds for other LLM tasks, such as bug fixing and code review, in future work.
- Analyzed Python, Java, and C++ codebases using CodeScene's CodeHealth (CH) maintainability metric
- Found weak but consistent correlation between CH and LLM-generated test effectiveness via coverage and mutation score testing
- Higher CH negatively correlated with input-token count, indicating cleaner code reduces token consumption in AI testing
Why It Matters
Highlights code maintainability as a key factor for both the quality and cost-efficiency of LLM-powered testing tools.