Automated Testing Framework for a Mobile Advertising SDK Using Cucumber and Appium
The article describes a comprehensive automated testing solution for a mobile advertising SDK that combines UI automation with Appium, behavior‑driven test management with Cucumber, dynamic request/response mocking via anyproxy, and JSON‑schema validation to improve test efficiency, reliability, and coverage.
The document introduces an advertising SDK and explains that frequent releases and integration with multiple ad platforms have created tight testing schedules and complex data‑validation challenges.
To address these issues, the team proposes an automated testing approach that aims to increase efficiency, ensure accurate point‑tracking data, and provide a reusable solution for other SDK teams.
Basic test scenarios include requesting ads, capturing network traffic with Fiddler, mocking diverse ad responses, displaying ads, and verifying impression and click tracking data.
The overall architecture is divided into three layers: a framework layer (using open‑source tools), a logic layer (implementing test case steps), and a data layer (storing test cases and mock data).
The control server acts as the brain of the system, managing test case execution, coordinating the demo app and mock server, and performing result validation. It uses Cucumber for BDD‑style case description and Appium to drive UI interactions on the demo app.
The mock server is built on Alibaba's anyproxy, allowing dynamic capture and mocking of network traffic. Mock rules are defined in JSON configuration files, and the server can switch rules on‑the‑fly based on control signals.
Example Cucumber step definitions (Java) are shown below:
@假设("^caseID\"([^\"]*)\"$")
public void getCaseID(String arg0) throws Throwable {
// Write code here that turns the phrase above into concrete actions
}
@假设("^打开原生广告界面$")
public void openNativeActivity() throws IOException {}
@并且("^填写广告条数\"([^\"]*)\"$")
public void fillInAdNum(String adnum) throws IOException {}
@当("^点击按钮\"([^\"]*)\"$")
public void clickButton(String btnType) {}
@那么("^请求及字段值校验如下$")
public void checkUrlField(List list) {}For data validation, JSON‑schema is used to define the expected structure and constraints of request and tracking payloads. An example of a JSON schema generated from sample data is provided:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {"description": "The unique identifier for a product", "type": "integer"},
"name": {"description": "Name of the product", "type": "string"},
"price": {"type": "number", "minimum": 0, "exclusiveMinimum": true}
},
"required": ["id", "name", "price"]
}
}Running the framework in a CI environment has reduced regression testing time from 10 hours per run to 0.5 hours, automated 25 % of total test cases (with a target of 40 %), and significantly lowered the risk of missed tracking errors in production.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.