LLM-assisted Mutation for Whitebox API Testing

Jia Li, Jiacheng Shen, Yuxin Su, Michael R. LyuarXiv 2025 · DOI

Introduction

Testing REST APIs is a cornerstone of modern software reliability, but achieving high code coverage is notoriously difficult. While "whitebox" testing tools—which utilize source code to guide their search—outperform "blackbox" alternatives, they frequently encounter "fitness plateaus." These occur when random mutations to an API request fail to satisfy strict code conditions, such as complex regular expressions or precise numeric constraints.

A new research paper, "MioHint: LLM-Assisted Request Mutation for Whitebox REST API Testing," introduces a novel framework to overcome these limitations by pairing Large Language Models (LLMs) with surgical static analysis.

The Challenge: The Fitness Plateau

Automated API testing typically relies on Search-Based Software Testing (SBST). Tools like EvoMaster generate and mutate API requests to trigger new code paths. However, if a line of code only executes when an input matches a specific format (e.g., a complex ID), the probability of a random mutator guessing it is near zero. This is a fitness plateau: the tool knows it hasn't hit the line, but it has no "gradient" or hint on how to get closer. Traditional symbolic execution can help but is often too "heavyweight" for complex real-world systems.

The MioHint Framework

MioHint treats the LLM as a "specialist" invoked only when standard search algorithms get stuck. The framework is built on three main pillars:

Pillar 1: Statement-Level Code Extraction (Value Expansion)

To avoid overwhelming the LLM's context window, MioHint performs a "def-use" analysis. It starts at a target branch and traces variables backward to identify exactly how API input fields influence that specific code path. This "Value Expansion" provides the LLM with a clean, relevant code slice rather than a noisy method-level context.

MioHint's Value Expansion and Code Extraction process

Pillars 2 & 3: Synergistic Search and LLM Mutation

MioHint allows a fast, traditional algorithm (MIO) to handle "easy" targets. When MIO plateaus, MioHint extracts the relevant code and requests a "mutation hint" from an LLM (GPT-4o). The prompt includes the code slice, the current failed request, and instructions to reason through the dependency chain using Chain-of-Thought prompting.

An example of MioHint generating a mutation hint to reach a specific code target

Evaluation and Results

The researchers evaluated MioHint using the EvoMaster Benchmark (EMB), covering 16 real-world REST API services and over 314,000 lines of code.

  • Mutation Accuracy: MioHint achieved a 67× improvement in mutation accuracy compared to the baseline.
  • Hard-to-Reach Targets: For branches covered less than 10% of the time by traditional tools, MioHint successfully reached 57.54%.
  • Line Coverage: On average, MioHint increased absolute line coverage by 4.95% across all services—a significant margin in automated testing.
  • Ablation Study: The "Value Expansion" static analysis was found to be critical; without it, the LLM's effectiveness in covering hard targets dropped by nearly half.

Conclusion

MioHint demonstrates that LLMs can act as effective "semantic solvers." Unlike symbolic execution, LLMs "understand" common library functions (like regex engines or parsers) based on their names and usage patterns, allowing them to bypass logic boundaries that stop traditional tools. While currently tailored for Java, the logic behind MioHint is generalizable. Future work may involve fine-tuning smaller, local models to reduce latency and costs, making high-coverage whitebox testing more accessible.

Summary updated

BibTeX
@misc{li2025llm,
  author = {Jia Li and Jiacheng Shen and Yuxin Su and Michael R. Lyu},
  title = {{LLM-assisted Mutation for Whitebox API Testing}},
  year = {2025},
  eprint = {2504.05738},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.05738},
}
Figure