Fundamentals 8 min read

Layered Testing Approach and Test Case Optimization for Transaction Services

This article introduces a layered testing methodology that separates presentation, core, and foundation layers, explains test case specifications and naming conventions, provides Java code examples for atomic, basic, and framework layers, and discusses optimization techniques such as data construction, regression testing, and exception validation to improve automation efficiency.

转转QA
转转QA
转转QA
Layered Testing Approach and Test Case Optimization for Transaction Services

Introduction The layered testing concept separates the system into three levels—presentation, core, and foundation—to achieve a clear testing architecture, improve manageability, and enable unified automation entry points.

Layered Testing Idea The presentation layer focuses on UI compatibility, the core layer handles main APIs, caches, and logs, while the foundation layer provides automated unit tests as the first gate in the testing pipeline.

Test Case Specification Test cases are divided into four layers:

pt_case

Test case layer where test cases are written and executed.

basic

Encapsulates the parameters required by the interface.

atomic

Calls the interface, obtains the return value, and performs context validation.

zzcommon

Utility package for HTTP client request handling.

Test Case Layer A test case combines multiple interface calls to simulate a business scenario, e.g., creating an order involves creating a product, creating the order, paying, shipping, and confirming receipt. Each test method represents one test case.

@Test(description = "Single inventory product confirm receipt flow test")
public void createInfo2ConfirmReceipt() throws Exception {
    // Publish normal product
    String infoId = Info.addNormalInfo(sellerId, "10", "5");
    // Place order
    String orderId = Trade.createOrder(buyerId, infoId);
    // Pay
    Trade.payOrder(orderId);
    // Ship
    Trade.deliverGoodWithExpress(orderId);
    // Confirm receipt
    Trade.confirmReceipt(orderId);
}

Basic Layer Constructs test data, for example, building an order request with buyer ID and product ID using a builder pattern.

public static String createOrder(String buyerId, String infoId) throws Exception {
    CreateOrderParam createOrderParam = new CreateOrderBuilder()
        .withBuyerId(buyerId)
        .withMultiProduct(true)
        .withSupportCent(true)
        .withShoppingCart(false)
        .build();
    CreateOrderResult result = createOrder(createOrderParam, errInfo);
    return result == null ? null : result.getOrderId();
}

Atomic Layer Interacts with backend services, receives third‑party responses, and validates them through assertions.

public static void checkResponseBackGroundCreateOrder(BackGroundCreateOrderResponseDTO response) throws Exception {
    if (!response.isSuccess()) {
        JSONObject respJson = new JSONObject();
        String respCode = response.getCode();
        String errMsg = response.getMessage();
        respJson.put("respCode", respCode);
        respJson.put("errMsg", errMsg);
        throw new ResponseCodeErrorException(JSONObject.toJSONString(respJson));
    }
}

Why Three‑Layer Test Structure? Separating responsibilities increases code reusability; changes in one layer require modifications only in that layer, reducing inter‑layer dependencies and standardizing development.

Context Validation Expected data is constructed and compared with actual responses using assertions; mismatches raise errors.

Test Case Optimization Includes classification by system and business line, naming conventions (lowercase package names, PascalCase class names, camelCase methods/variables, no pinyin), regression testing for each requirement, and exception validation for error responses.

{"successData":false,"code":"10018","success":false,"message":"The product has already been ordered!"}

Data Construction Optimization Replaces numerous setter calls with the Builder pattern to reduce redundancy and improve readability.

Conclusion Continuous improvement of test cases shortens functional testing time, enables developers to self‑test before release, and, with ongoing optimization, leads to a stable and mature testing framework.

JavaTestingsoftware qualityAPI automationtest case designlayered architecture
转转QA
Written by

转转QA

In the era of knowledge sharing, discover 转转QA from a new perspective.

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.