ConUT: Condition-Aware Test Generation for Complex Java Code
Automatically generating high-coverage unit tests for complex Java methods remains a formidable challenge, particularly when execution paths are guarded by intricate control-flow nesting and cross-class state dependencies. Existing LLM-based approaches predominantly follow a \textit{goal-driven paradigm}, relying on unguided code synthesis within a vast search space to satisfy coverage objectives. Lacking explicit guidance on \textit{how} to construct the precise object states required for complex predicates, these methods suffer from a construction-reachability gap, ultimately resulting in insufficient coverage for complex methods.
This paper introduces ConUT, a condition-aware unit test generation framework centered on the paradigm of Configuration-Driven Guidance, which is a strategy that bridges the gap between abstract branch targets and concrete code realization by providing the LLM with structured instantiation recipes. Our core insight is that the implicit causal chain leading to a target branch can be explicitly manifested via static analysis and distilled into structured guidance. ConUT utilizes \textit{Backward Dependency Tracing} (BDT) to identify the fields and method calls that influence predicates, and distills these findings into structured Configuration Templates ($C_{cfg}$). These templates serve as a ``semantic roadmap,'' pruning the LLM’s search space and transitioning it from a stochastic generator into a guided logic realizer.
We evaluate ConUT on eight real-world Java projects characterized by high-complexity ``logic hotspots''. Experimental results demonstrate that ConUT significantly outperforms state-of-the-art baselines, achieving an average branch coverage of \textbf{72.84%} and line coverage of \textbf{83.87%}. Notably, ConUT exceeds the best baseline by \textbf{11.94%} branch coverage improvement while utilizing \textbf{67% fewer} test cases. These findings prove ConUT’s effectiveness in bridging the gap between program analysis and LLM synthesis through explicit causal-chain manifestation.