Back to Repositories

Testing XLS 2003 File Reading and Bean Mapping in EasyExcel

This test suite evaluates Excel file handling and bean mapping functionality in EasyExcel, focusing on XLS 2003 format compatibility. It includes tests for reading Excel files and verifying bean property mapping with case sensitivity considerations.

Test Coverage Overview

The test suite covers two main areas of functionality:

  • Synchronous reading of XLS 2003 format files using EasyExcel’s read API
  • Bean property mapping validation with different case variations using BeanMap utilities
Integration points include FastJSON for data serialization and SLF4J for logging test outputs.

Implementation Analysis

The testing approach utilizes JUnit Jupiter for test execution and verification. The implementation demonstrates both direct file reading patterns and complex bean mapping scenarios, with particular attention to case-sensitive property access. The tests leverage EasyExcel’s synchronous reading API (doReadSync) for Excel data extraction.

Technical patterns include proxy generation debugging and custom class writing location configuration for development purposes.

Technical Details

Key technical components include:

  • EasyExcel core library for Excel operations
  • CGLIB for bean manipulation
  • FastJSON2 for data serialization
  • SLF4J for logging
  • JUnit Jupiter test framework
  • Custom proxy generation configuration for debugging

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Isolated test methods for distinct functionality
  • Proper logging implementation for test output verification
  • Configuration of debugging tools for development support
  • Clear separation of file reading and bean mapping tests
  • Effective use of utility classes for bean manipulation

alibaba/easyexcel

easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Xls03Test.java

            
package com.alibaba.easyexcel.test.temp;

import java.util.List;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.support.cglib.core.DebuggingClassWriter;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.fastjson2.JSON;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 临时测试
 *
 * @author Jiaju Zhuang
 **/

public class Xls03Test {
    private static final Logger LOGGER = LoggerFactory.getLogger(Xls03Test.class);

    @Test
    public void test() {
        List<Object> list = EasyExcel.read("D:\\test\\8.xls").sheet().doReadSync();
        for (Object data : list) {
            LOGGER.info("返回数据:{}", JSON.toJSONString(data));
        }
    }

    @Test
    public void test2() {
        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY,
            "/Users/zhuangjiaju/IdeaProjects/easyexcel/target");

        CamlData camlData = new CamlData();
        //camlData.setTest("test2");
        //camlData.setAEst("test3");
        //camlData.setTEST("test4");

        BeanMap beanMap = BeanMapUtils.create(camlData);

        LOGGER.info("test:{}", beanMap.get("test"));
        LOGGER.info("test:{}", beanMap.get("Test"));
        LOGGER.info("test:{}", beanMap.get("TEst"));
        LOGGER.info("test:{}", beanMap.get("TEST"));

    }
}