Editor’s introduction
The study evaluates IntTestGen, an LLM-based system designed to generate integration tests for Java code by leveraging dependency usage patterns from real project code. It uses a ClassIndex, Markov typestate model, and experience memory to enforce constraints on object construction, API sequences, and component interactions, improving coverage over existing LLM and search-based baselines. The approach outperforms PANTA and EvoSuite in line and branch coverage, as well as mutation score, on Defects4J and Deps4J benchmarks. Ablation studies confirm each component contributes meaningfully to performance. The system incurs higher total token and time costs than PANTA due to iterative refinement, but per-iteration costs are competitive and runtime is significantly lower. Despite this, IntTestGen remains practical, averaging under two minutes and fewer than 60k tokens per method. The findings suggest future work combining IntTestGen with fuzzing or grammar-aware input generation to enhance feedback loops for parser-driven components.
Introduction
Software testing is essential for identifying defects early in the development lifecycle. While unit testing has long been the cornerstone of automated test generation research, it addresses only part of the testing problem. A unit test exercises a single class or method in isolation, typically using mocking frameworks (e.g., Mockito, PowerMock ) to replace real dependencies with simulated ones. This enables fast, deterministic checks, but it creates a fundamental blind spot: faults arising from interactions between components, such as invalid object construction, incorrect API call sequences, and behavior mismatches when a dependency’s implementation changes. Consider a streaming XML writer: a unit test with mocked dependencies passes even if the writer calls writeStartObjection without first invoking setNextName, because the mock silently accepts any call order. A real dependency, however, throws an IllegalStateException, exposing the protocol violation. Such integration faults are common in practice and motivate integration testing.
In this work, we focus on low-level integration testing: testing a class together with its real, in-project dependencies (i.e., classes within the same codebase that the class under test (CUT) calls or instantiates). Unlike end-to-end integration tests that span multiple services or external systems, low-level integration tests operate within a single module or repository. They complement unit tests by validating that components work together correctly, while remaining fast enough to run in continuous integration (CI) pipelines. Despite their importance, existing automated test generation tools largely ignore low-level integration tests. Traditional automated unit-test generators (e.g., EvoSuite and Randoop ) can execute real dependencies while testing a target class, but do not explicitly optimize dependency interactions or coverage of dependency code, that is, code the target class depends on. Recent LLM-based approaches have significantly advanced automated software testing in reducing compilation/execution errors and improving test coverage. However, they either operate at the method level without handling dependencies, or rely on mocking frameworks to isolate the CUT. System-level integration testing tools (e.g., EvoMaster, RESTler ) target REST API endpoints from API specifications. These tools differ fundamentally from this work, where we generate tests directly from source code to exercise the CUT together with its real, in-project dependencies at the class level. To the best of our knowledge, no existing automated approach targets class-level integration test generation. Generating such tests poses unique challenges: the generator must correctly instantiate dependency objects (including abstract types), resolve imports, and respect stateful API protocols, which requires project-specific knowledge that LLMs do not inherently possess.
Not knowing vs. Not following. We characterize these challenges through two root causes of hallucination. Not knowing arises when an LLM lacks project-specific context to correctly construct and use dependencies. In those cases, LLMs tend to fabricate nonexistent factory methods or use incorrect constructor signatures. Not following occurs when the model receives correct contextual information but fails to adhere to it, producing tests that violate project-specific constraints such as API call ordering or symbol correctness. These two failure modes demand complementary strategies: enriching generation with mined project knowledge, and enforcing constraints explicitly during repair.
Approach
In the preparation stage, IntTestGen analyzes the target repository to construct three project-specific artifacts that support different parts of the integration testing pipeline. The code property graph (CPG) captures dependency usage in the repository and supports slicing-based retrieval of real object construction and API-call examples. The ClassIndex records project-visible classes, methods, constructors, and imports, providing a basis for detecting hallucinated or inconsistent symbols. The initial Markov typestate model captures likely valid method-call orders for stateful APIs, providing a basis for detecting illegal call sequences. Together, these artifacts connect context acquisition and constraint enforcement: the CPG helps the model understand how dependencies are used, while the ClassIndex and typestate model help ensure that generated or repaired tests adhere to project-specific symbol and protocol constraints.
It is worth clarifying the scope of project access in IntTestGen. The CPG, ClassIndex, and typestate model provide only construction context: they inform the Generator and Fixer about valid ways to instantiate and invoke dependencies in the generated test code. At execution time, generated tests exercise the real dependency implementations within the same Maven module as the CUT. IntTestGen never instruments, modifies, or mocks dependency behavior; project-wide analysis serves solely to make generated tests compile and execute against real dependencies. This mirrors how a developer writes an integration test: reading related source code to learn the API, then running the test against the actual components.
After preparation, IntTestGen enters an iterative plan–generate–validate–fix loop composed of five agents: Initializer, Planner, Generator, Validator, and Fixer. The Initializer prepares the analysis artifacts and testing environment, the Planner creates a test plan by selecting uncovered CUT paths to target, the Generator produces candidate tests, the Validator compiles and executes generated tests, and the Fixer repairs failing tests based on validation feedback. Through this iterative collaboration, the framework progressively improves test quality and coverage over multiple rounds.
Fixer
The Fixer addresses the second class of limitations (“not following”), which occur when the model fails to adhere to required constraints even when they are explicitly provided. Instead of relying on a single repair step, the Fixer performs a two-stage correction process for each failing test. The process starts with the failing test and its compiled error signals from execution and compilation. IntTestGen first generates an initial repair based on this feedback (Fixer I). The resulting test is then checked against three constraint levels: (i) symbol-level constraints from the ClassIndex, which ground the repair in project-visible classes, constructors, methods, and imports before any higher-level reasoning is applied; (ii) protocol-level constraints from the Markov typestate model that enforce valid API call ordering; and (iii) iteration-level guidance from experience memory, which contains gold tests, fix recipes, and anti-patterns. Gold tests are previously generated tests that compile and pass, fix recipes summarize successful edits that repaired earlier failures, and anti-patterns record unfixable tests or repair attempts that should not be repeated. If any violation is detected, a second repair is triggered, conditioned on the identified constraint violations (Fixer II). In this second repair, the model must also produce a structured justification explaining why the revised test satisfies all constraints and resolves the original failure. This is a key design choice in our approach: by forcing the model to explicitly explain its own correction, we make constraint satisfaction part of the generation process rather than an implicit expectation. The justification requires the model to reflect on symbol-, protocol-, and iteration-level constraints, strengthening adherence during repair.
Symbol-level constraints. Symbol-level failures, including fabricated classes, invalid method calls, incorrect constructor signatures, and illegal abstract instantiations, occur when the model produces identifiers that do not exist in the project. To eliminate such errors, the Fixer performs deterministic symbol verification using the ClassIndex.
For each failing test, all referenced symbols are resolved against the ClassIndex, and invalid references are replaced with valid candidates. Method calls are checked against the index entries, and mismatches are replaced with the closest valid alternative based on string similarity or removed if no safe replacement exists. Constructor invocations are similarly validated against the recorded constructor signatures, ensuring arity and type consistency.
RQ3 Results (Ablation Study)
Usage retrieval provides usage patterns to help IntTestGen instantiate objects. When it is removed, average DepLC drops from 1197 to 903 on Defects4J and from 279 to 129 on Deps4J, the largest reduction of any ablation on both datasets. It also causes broad declines in line, branch, and mutation score: on Defects4J, average line coverage drops from 88.82 to 79.01, branch coverage from 83.74 to 72.25, and mutation score from 52.00 to 40.44; on Deps4J, the corresponding averages fall from 75.98 to 57.86, from 58.12 to 48.68, and from 47.09 to 44.23. This suggests that repository-specific usage examples do more than improve instantiation correctness: they also help the model generate tests that execute deeper behaviors once dependencies are reached.
Symbol-level constraints have a more moderate but still important effect. At the dataset level, -Sym lowers all four metrics on both benchmarks relative to the full method: on Defects4J, line coverage falls from 88.82% to 80.69%, branch coverage from 83.74% to 74.88%, mutation score from 52.00% to 43.11%, and DepLC from 1197 to 934; on Deps4J, the corresponding averages decrease from 75.98% to 64.77%, from 58.12% to 53.82%, from 47.09% to 44.55%, and from 279 to 178. Although the drop is less severe than for usage retrieval, it remains substantial. This is consistent with the role of symbol constraints in preventing invalid references and hallucinated APIs during repair. Interestingly, symbol-level constraints can occasionally hurt individual project metrics. For example, the full IntTestGen achieves a lower mutation score than -Sym on Cli in Defects4J and on A2A and ADK in Deps4J, and lower line or branch coverage on projects such as Cli, Codec, Gson, Jsoup, and ADK. Further investigation suggests that ambiguous symbol resolution is a plausible cause. For instance, ADK contains multiple classes with the same simple name across different packages and dependencies: Schema may refer to com.google.genai.types.Schema, com.google.adk.tools.Annotations.Schema, com.google.cloud.bigquery.Schema, or org.apache.arrow.vector.types.pojo.Schema. When the import context is incomplete, IntTestGen may deterministically prefer a project-local com.google.adk.* type over the intended external type due to package-prefix similarity. Thus, in projects with many homonymous APIs, symbolic resolution can occasionally select a wrong but plausible symbol. This limitation points to a future research direction: designing context-aware symbol resolution mechanisms that combine import history, call-site semantics, dependency usage patterns, and validation feedback to disambiguate symbols more reliably.
Finally, iteration-level constraints appear to have the weakest influence among the four ablated components, yet their contribution remains substantial. The -Iter variant causes smaller drops than removing usage retrieval, symbol-level constraints, or protocol-level constraints, yet all metrics still decline substantially relative to the full method. On Defects4J, line coverage decreases from 88.82% to 80.81%, branch coverage from 83.74% to 74.51%, mutation score from 52.00% to 42.00%, and DepLC from 1197 to 1006. On Deps4J, the corresponding averages decrease from 75.98% to 65.94%, from 58.12% to 53.32%, from 47.09% to 45.97%, and from 279 to 137. Unlike usage retrieval, symbol-level constraints, and protocol-level constraints, which are derived from source-code analysis, iteration-level constraints are learned from previous generation and repair experience. They operate across iterations by preserving useful experience, discouraging repeated failures, and reusing successful repair patterns. These results motivate a promising future direction: to incorporate richer memory mechanisms, such as MemoRAG or dual-memory designs, to better organize past failures, successful repairs, dependency interactions, and reusable testing patterns.
Threats to Validity
Construct Validity. A potential threat to construct validity is whether the selected metrics accurately reflect a test generation approach’s effectiveness and efficiency. Standard metrics such as line coverage, branch coverage, and mutation score capture only part of test quality. For example, coverage may overestimate behavioral quality, while the mutation score can be influenced by the number and strength of assertions. To mitigate this threat, we use multiple complementary metrics, including line coverage, branch coverage, mutation score, project DepLC, number of iterations, token cost, and wall-clock time. Together, these metrics provide a more comprehensive view of both effectiveness and efficiency. In particular, we introduce the DepLC metric to measure how much real dependency code is exercised beyond the CUT, which is especially relevant for evaluating integration test generation.
Internal Validity. Threats to internal validity mainly arise from the configurations of IntTestGen and PANTA, as well as the choice of the backbone LLM. First, different hyperparameter settings may affect the comparison between the two tools. To mitigate this threat, we use identical settings for both IntTestGen and PANTA whenever possible, including the same context size, temperature, maximum output length, LLM, tokenizer, and hardware environment. We also set the same generation budget for both tools, based on the experimental setting recommended by PANTA, to ensure they have sufficient opportunity to converge across all projects and demonstrate their full capabilities. Second, the choice of LLM may influence the results. We select Qwen3-Coder-30B-A3B-Instruct-FP8, one of the latest and strongest small-scale open-source code models, considering both its coding capability and resource requirements. Larger LLMs may improve absolute performance, but benchmarking different LLMs is not the objective of this study, and newer LLMs may have been trained on the benchmark datasets, introducing further data leakage. Since both IntTestGen and PANTA use the same backbone model, stronger LLMs would likely benefit both approaches without altering the fairness of the comparison.
External Validity. Threats to external validity concern whether our results generalize to other Java projects. To mitigate this threat, we evaluate IntTestGen on Defects4J, a widely used Java testing benchmark containing 14 projects from diverse domains. However, because Defects4J was curated more than a decade ago, some of its code may have appeared in Qwen3-Coder’s training corpus, raising a potential data leakage concern. To further assess generalizability and reduce this risk, we curate Deps4J, a new benchmark comprising Java projects created after the Qwen3-Coder training cutoff date. The consistent results of IntTestGen on both Defects4J and Deps4J suggest that the observed improvements are not limited to a single benchmark or caused by benchmark memorization. Nevertheless, our evaluation remains limited to Java projects and a single backbone LLM, so future studies should extend to other languages, repositories, and models.
Conclusion
This paper presents IntTestGen, an LLM-based approach for generating low-level integration tests for Java. Unlike prior LLM-based approaches that target unit-level testing with mocked dependencies, IntTestGen directly exercises real project dependencies by combining context-enriched generation with constraint-enforced repair. It addresses two major sources of hallucination in dependency-aware test generation: not knowing, mitigated by dependency-usage retrieval, and not following, mitigated by symbol-, protocol-, and iteration-level constraints.
Our evaluation on Defects4J and Deps4J shows that IntTestGen consistently improves test quality and dependency coverage over both the LLM-based SOTA baseline PANTA and the search-based SOTA baseline EvoSuite. On Defects4J, IntTestGen improves average line coverage from 68.83% to 88.82% and from 61.52% (EvoSuite) to 88.82%, branch coverage from 58.84% to 83.74%, mutation score from 38.33% to 52.00%, and DepLC from 819 to 1197, while generating fewer tests than PANTA. On Deps4J, IntTestGen again improves line, branch, and dependency coverage, while maintaining comparable mutation scores. Although these gains require higher total generation cost in tokens and time, the cost remains practical, averaging 108.97 seconds and 26.59k tokens per method on Defects4J, and 69.85 seconds and 25.46k tokens per method on Deps4J. An ablation study shows that all four major components of IntTestGen contribute positively, including usage retrieval, symbol-level constraints, protocol-level constraints, and iteration-level constraints.
Future directions include developing richer memory mechanisms to better organize past failures and successful repairs, improving context-aware symbol resolution for projects with many homonymous APIs, evaluating the readability and maintainability of generated tests, extending IntTestGen to other strongly typed languages, and investigating additional baselines such as larger LLMs and LLM-based coding agents.


