Call-Chain-Aware LLM-Based Test Generation for Java Projects

Guancheng Wang, Qinghua Xu, Lionel C. Briand, Zhaoqiang Guo, Kui LiuarXiv 2026

TL;DR

This paper introduces CAT, a novel approach for generating Java unit tests using Large Language Models (LLMs). CAT significantly improves test coverage by explicitly incorporating call-chain and dependency information into LLM prompts, addressing a key limitation of existing methods that struggle with complex inter-class dependencies.

What Problem Does This Paper Address?

Writing high-quality unit tests is a labor-intensive task for software engineers. While LLMs show promise in automating this, current methods often fall short for complex Java projects. These projects feature intricate inter-class dependencies and deep call chains, which existing LLM-based test generation techniques, primarily relying on execution-path feedback, fail to adequately model. This limitation hinders their ability to generate valid and effective tests for real-world software.

Methods

CAT employs a two-phase approach: generation and fixing. The core innovation lies in its static analysis framework, which systematically extracts:

  • Call-Chain Information: Identifies potential invocation paths from entry points to the target method, including caller-callee relationships.
  • Dependency Context: Resolves object constructors and third-party dependencies required for valid execution.

This extracted context is then integrated into LLM prompts. The approach prioritizes direct invocation of focal methods but also leverages call-chain information for indirect invocation when direct calls are insufficient. A fixing phase iteratively repairs failing tests based on error messages.

Datasets

  • Defects4J: A widely used benchmark for evaluating software testing and debugging techniques.
  • Four real-world GitHub projects: These projects were released after the LLM's cut-off date, ensuring they were not part of the training data and offering a more realistic evaluation of generalization. These projects are also noted to be more complex and multi-module compared to Defects4J.

Key Insights and Ideas

  • Context is King: Simply guiding LLMs with execution paths isn't enough for complex projects. Explicitly providing call-chain and dependency context is crucial for generating effective tests.
  • Static Analysis is Key: A dedicated static analysis framework is essential for systematically capturing the necessary contextual information that LLMs can leverage.
  • Direct vs. Indirect Invocation: The approach balances prioritizing direct invocation of target methods with using call-chain information for indirect invocation when direct calls are problematic.
  • Overloaded Methods are a Challenge: The approach handles overloaded methods by generating tests for each focal method individually, avoiding ambiguity.
  • Naive Combination Doesn't Always Work: Simply merging uncovered-path information with call-chain context didn't yield consistent improvements, suggesting that integrating diverse signals is a complex challenge.

Key Results

  • Defects4J: CAT improved line coverage by 18.04% and branch coverage by 21.74% over PANTA (state-of-the-art). Even against a time-bounded variant of PANTA, CAT showed significant gains.
  • Unseen Projects: CAT achieved even larger improvements on more complex, unseen projects, with average gains of 25.09% in line coverage and 25.91% in branch coverage over PANTA.
  • Ablation Study: CATvanilla (without call-chain and dependency context) showed substantially lower coverage, highlighting the significant contribution of these features.

Limitations and Future Work

  • LLM Choice and Configuration: The performance of LLM-based approaches can be sensitive to the choice of LLM, prompt design, and parameter settings.
  • Project Complexity: While CAT shows strong generalization, coverage on unseen, more complex projects was lower, indicating that dependency-rich systems remain challenging.
  • Integrating Heterogeneous Signals: Future work could explore more principled methods for integrating various signals (e.g., execution paths, input-output relationships) beyond static analysis.
  • Dynamic Dependencies: Advanced techniques for modeling dynamic dependencies and improving context selection under long call chains are suggested.

Summary updated

BibTeX
@misc{wang2026call,
  author = {Guancheng Wang and Qinghua Xu and Lionel C. Briand and Zhaoqiang Guo and Kui Liu},
  title = {{Call-Chain-Aware LLM-Based Test Generation for Java Projects}},
  year = {2026},
  eprint = {2604.22046},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2604.22046},
}
Figure