Chapter 9. Testing Spring Boot Applications for Increased Production Readiness
This chapter discusses and demonstrates core aspects of testing Spring Boot applications. While the subject of testing has numerous facets, I focus upon the fundamental elements of testing Spring Boot applications that dramatically improve the production readiness of each application. Topics include unit testing, holistic application testing using @SpringBootTest
, how to write effective unit tests using JUnit, and using Spring Boot testing slices to isolate test subjects and streamline testing.
Code Checkout Checkup
Please check out branch chapter9begin from the code repository to begin.
Unit Testing
Unit testing serves as a precursor to other types of application testing for good reason: unit testing enables a developer to find and fix bugs at the earliest possible stages of the develop+deploy cycle and as a result, to fix them at the lowest possible cost.
Simply put, unit testing involves validating a defined unit of code isolated to the maximum possible and sensible extent. A test’s number of outcomes increases exponentially with size and complexity; reducing the amount of functionality within each unit test makes each one more manageable, thus increasing the likelihood that all likely and/or possible outcomes are considered.
Only once unit testing is implemented successfully and sufficiently should integration testing, UI/UX testing, and so on be added to the mix. Fortunately Spring Boot incorporates ...
Get Spring Boot: Up and Running now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.