Operations 11 min read

Introduction to Qunit: Zero‑Intrusion Aspect Technology and Distributed Execution Platform

The article introduces Qunit, an API automation testing framework built on JUnit, explains its zero‑intrusion Java Agent aspect for mocking third‑party services, and describes a distributed execution platform that creates isolated environments to run tests in parallel, dramatically reducing overall test execution time.

Qunar Tech Salon
Qunar Tech Salon
Qunar Tech Salon
Introduction to Qunit: Zero‑Intrusion Aspect Technology and Distributed Execution Platform

Qunit Introduction

Qunit is an API automation testing framework developed by Qunar.com based on the JUnit framework, supporting HTTP, Dubbo RPC, and Hessian interfaces. It encapsulates common functionalities such as test data preparation, remote SQL execution, and API invocation into reusable tags, allowing testers to focus on test case design. Assertions are performed by diffing responses against baseline data.

1 Zero‑Intrusion Aspect Technology

1.1 Problems

When writing automation test cases, mocking third‑party interfaces faces challenges: complex data structures, heavy reliance on third‑party data, and the need to modify mock data across multiple dependent interfaces, which increases time cost.

1.2 Solution

The Java Agent provides instrumentation to redefine classes at runtime. Qunit uses a Catcher Agent module to modify bytecode, enabling dynamic recording and playback of third‑party data without altering the target system's code. The agent operates in isolation from production environments.

Before bytecode modification:

public ReturnType method(ParamsType[] params) throws Exception{
    //something
}

After bytecode modification:

private ReturnType $catcher$method(ParamsType[] params) throws Exception{
    //something
}
public ReturnType method(ParamsType[] params) throws Exception{
    ReturnType returnObj;
    try{
        if(needMock(className, methodName, params)){
            returnObj = mock(className, methodName, params);
        } else {
            returnObj = $catcher$method(params);
        }
    } finally {
        if(needCollect(className, methodName)){
            collect(className, methodName, params, returnObj);
        }
    }
    return returnObj;
}

Key points:

Catcher Agent wraps target code with additional logic.

needMock decides whether to use mock data or real calls.

needCollect controls data recording.

Data collection is asynchronous, not affecting runtime.

Qunit provides two modes:

Recording mode: captures third‑party responses locally for later use and parameterization.

Playback mode: uses stored mock data to simulate third‑party services during testing.

1.3 Qunit Usage Example

Define Catcher Pointcut in Service

<pointcut id="test-fetchPost"
    serverName="10.10.10.10"
    application="testApp"
    location="com.qunat.test.UpopHttpSender"
    methodName="fetchPost"
    type="CLASS"
    desc="UpopHttpSender.fetchPost()的切面"/>

Use in Automated Test Case

<case>
  <catch pointcut="test-fetchPost" mock_target="OUTPUT">
      {"respCode":"00","respMsg":"成功"}
  </catch>
  <call service="TestCatcher">
      <param name="abc" role="admin"/>
  </call>
  <dataassert />
</case>

The test executes TestCatcher, mocking the third‑party interface with the provided JSON response.

2 Distributed Execution Platform

2.1 Problems

As Qunit grew, test case volume increased, leading to long execution times (up to an hour). Single‑threaded Maven test execution became a bottleneck, prompting the need for parallel execution.

2.2 Solution

The platform creates multiple isolated test environments via the Noah environment management system, distributes test files based on previous execution duration, runs them in parallel, and aggregates results in real time. This reduces overall test time and supports scheduling, environment management, reporting, and coverage statistics.

Architecture diagram:

3 Summary

Zero‑intrusion aspect technology, built with a Java Agent, enables the Catcher system to record and replay method return values without modifying source code. The distributed execution platform shortens test cycles by parallelizing execution across multiple isolated environments and will later serve as a company‑wide solution for various automated testing frameworks.

JavaautomationMockDistributed TestingJava agentAPI testing
Qunar Tech Salon
Written by

Qunar Tech Salon

Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.