Back to Repositories

Testing KdNiao Express Tracking Integration in RuoYi-Vue-Pro

This integration test suite validates the KdNiao Express delivery tracking functionality in the RuoYi Vue Pro application. It tests the integration between the application and KdNiao’s express tracking API service, ensuring reliable logistics tracking capabilities.

Test Coverage Overview

The test suite focuses on validating express delivery tracking functionality through KdNiao’s API integration. Key areas covered include:

  • Express tracking information retrieval using logistics tracking numbers
  • Integration with KdNiao’s REST API endpoints
  • Proper handling of express carrier codes and tracking numbers
  • Response parsing and mapping to DTOs

Implementation Analysis

The testing approach utilizes Spring’s RestTemplate for HTTP communications and JUnit for test execution. The implementation demonstrates:

  • Clean separation of configuration and test logic
  • Proper initialization of test dependencies using @BeforeEach
  • Use of DTOs for request/response handling
  • Integration with external API using proper authentication

Technical Details

Testing infrastructure includes:

  • JUnit Jupiter test framework
  • Spring Boot’s RestTemplateBuilder
  • Lombok for logging capabilities (@Slf4j)
  • Custom JSON utilities for response handling
  • TradeExpressProperties for configuration management

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Proper test isolation and setup
  • Clear test method naming conventions
  • Use of @Disabled annotation for integration tests
  • Externalized configuration management
  • Structured error handling and logging

yunaiv/ruoyi-vue-pro

yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientIntegrationTest.java

            
package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl;

import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kdniao.KdNiaoExpressClient;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * {@link KdNiaoExpressClient} 的集成测试
 *
 * @author jason
 */
@Slf4j
public class KdNiaoExpressClientIntegrationTest {

    private KdNiaoExpressClient client;

    @BeforeEach
    public void init() {
        RestTemplate restTemplate = new RestTemplateBuilder().build();
        TradeExpressProperties.KdNiaoConfig config = new TradeExpressProperties.KdNiaoConfig()
                .setApiKey("cb022f1e-48f1-4c4a-a723-9001ac9676b8")
                .setBusinessId("1809751");
        client = new KdNiaoExpressClient(restTemplate, config);
    }

    @Test
    @Disabled("集成测试,暂时忽略")
    public void testGetExpressTrackList() {
        ExpressTrackQueryReqDTO reqDTO = new ExpressTrackQueryReqDTO();
        reqDTO.setExpressCode("STO");
        reqDTO.setLogisticsNo("777168349863987");
        List<ExpressTrackRespDTO> tracks = client.getExpressTrackList(reqDTO);
        System.out.println(JsonUtils.toJsonPrettyString(tracks));
    }

}