[JAVA] Test the contents of an Excel file with JUnit

How to test the contents of the Excel file output to HttpServletResponse using the POI library with JUnit. I'm addicted to reading from response, so I'll leave it as a reminder.

In the test class, MockHttpServletResponse is used to generate a response.

//Response passed to the test target class
MockHttpServletResponse response = new MockHttpServletResponse();

//Read the Excel file output from the response processed by the test target class with InputStream
InputStream inputStream = new ByteArrayInputStream(response.getContentAsByteArray());

Since the xlsx format is a binary file, It can be read by ʻInputStream using getContentAsByteArray () of HttpServletResponse`.

The rest

Workbook workbook = WorkbookFactory.create(inputStream);

Open the Excel file with and test the contents cell by cell.

Recommended Posts

Test the contents of an Excel file with JUnit
Overwrite the contents of config with Spring-boot + JUnit5
Replace the contents of the Jar file
Create an excel file with poi
Check the contents of params with pry
Format the contents of LocalDate with DateTimeFormatter
[Java] Get MimeType from the contents of the file with Apathce Tika [Kotlin]
Verify the contents of the argument object with Mockito
Easy JUnit test of Elasticsearch 2018 version with embedded-elasticsearch
Unit test with Junit.
List the contents of categories created with Active Hash
[JUnit5] Dealing with "the reference of assertEquals is ambiguous"
Get the name of the test case in the JUnit test class
Test Web API with junit
[JUnit] Test the thrown exception
How to change the contents of the jar file without decompressing
The basics of the process of making a call with an Android app
[Rails] Check the contents of the object
The story of toString () starting with passing an array to System.out.println
[Java] Test private methods with JUnit
EXCEL file update sample with JAVA
Overwrite upload of file with the same name with BOX SDK (java)
Test Spring framework controller with Junit
[Ruby] Display the contents of variables
How to get the length of an audio file in java
Examine the contents of the WAR file generated by the project created by Spring Initializr
The end of catastrophic programming # 01 "Do it with the absolute value of an integer"
How to convert an array of Strings to an array of objects with the Stream API
After all I wanted to preview the contents of mysql with Docker ...
With EqualsVerifier, the equals () test was instant
Check the contents of the Java certificate store
Control test order in Junit4 with enumeration
Test the integrity of the aggregation using ArchUnit ②
Memo: [Java] Check the contents of the directory
Folding and unfolding the contents of the Recyclerview
Compare the elements of an array (Java)
[Ruby] Cut off the contents of twitter-ads
Check the processing contents with [rails] binding.pry
About the treatment of BigDecimal (with reflection)
How to test private scope with JUnit
JUnit 5 gradle test fails with lombok annotation
Java automated test implementation with JUnit 5 + Gradle
The contents of the data saved by CarrierWave.
[Java] [Spring] Test the behavior of the logger
Test the integrity of the aggregation using ArchUnit ③
Inspect the contents of log output during Java unit test (no mock used)
The story of making an electronic New Year's card app with Vue.js + Rails
How to perform UT with Excel as test data with Spring Boot + JUnit5 + DBUnit
How to create an Excel form using a template file with Spring MVC
[Java] How to test for null with JUnit
I rewrote the Rails tutorial test with RSpec
[CircleCI 2.0] [Java] [Maven] [JUnit] Aggregate JUnit test results with CircleCI 2.0
[Java] Creating an Excel file using Apache POI
Customize how to divide the contents of Recyclerview
Java automated test implementation with JUnit 5 + Apache Maven
How to test interrupts during Thread.sleep with JUnit
Manage the version of Ruby itself with rbenv
The story of tuning android apps with libGDX
RSpec-Results of reviewing the test code for'users validation'
I want to var_dump the contents of the intent
Rename the package name of the existing jar file