Testing Headerless Excel Operations in alibaba/easyexcel
This test suite validates EasyExcel’s functionality for handling Excel files without headers across different formats (XLSX, XLS, CSV). It demonstrates the framework’s capability to read and write data when header rows are explicitly disabled.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
alibaba/easyexcel
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/NoHeadDataTest.java
package com.alibaba.easyexcel.test.core.head;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
/**
* @author Jiaju Zhuang
*/
@TestMethodOrder(MethodOrderer.MethodName.class)
public class NoHeadDataTest {
private static File file07;
private static File file03;
private static File fileCsv;
@BeforeAll
public static void init() {
file07 = TestFileUtil.createNewFile("noHead07.xlsx");
file03 = TestFileUtil.createNewFile("noHead03.xls");
fileCsv = TestFileUtil.createNewFile("noHeadCsv.csv");
}
@Test
public void t01ReadAndWrite07() {
readAndWrite(file07);
}
@Test
public void t02ReadAndWrite03() {
readAndWrite(file03);
}
@Test
public void t03ReadAndWriteCsv() {
readAndWrite(fileCsv);
}
private void readAndWrite(File file) {
EasyExcel.write(file, NoHeadData.class).needHead(Boolean.FALSE).sheet().doWrite(data());
EasyExcel.read(file, NoHeadData.class, new NoHeadDataListener()).headRowNumber(0).sheet().doRead();
}
private List<NoHeadData> data() {
List<NoHeadData> list = new ArrayList<NoHeadData>();
NoHeadData data = new NoHeadData();
data.setString("字符串0");
list.add(data);
return list;
}
}