Cut your Spring Boot Test Suite from 10 to 2 Minutes ⚡
How Test Slicing Changes Everything 🍃
Hi Mailwal,
Over the past few days, I've shown you the pain and cost of bad testing.
Now I want to show you how to fix it.
The problems are always similar:
Every test class uses @SpringBootTest.
Every single test boots up the entire application - all the beans, all the auto-configuration, the database connections, the message queues, the security setup, everything.
For a modest application with 50 test classes, that's 50 complete application startups.
Each startup takes 10-15 seconds. 50 × 15 seconds = 12+ minutes just in application startup time.
Testing a REST controller? @WebMvcTest loads just the web layer - no database, no messaging, no full application context.
Testing a repository? @DataJpaTest loads just JPA and the database - no web layer, no full application context.
We audited their 120 test classes:
18 minutes to 4 minutes with one technique.
Loads: Spring MVC, controllers, Jackson, validation
Doesn't load: Database, security (unless you want it), other layers
@DataJpaTest - Testing repositories
Loads: JPA, your repositories, an in-memory database
Doesn't load: Web layer, services, full application
@SpringBootTest - Integration tests only
Use this for tests that need the full application wired together
About 10-15% of your tests should use this
Change @SpringBootTest to @WebMvcTest.
Add @MockBean for any dependencies the controller needs.
Run the test. Watch it go from 15 seconds to 2 seconds.
That feeling? That's the start of getting your time back.
Tomorrow, I'll show you technique #2: Spring TestContext Context caching. This is what takes you from minutes to seconds.
PS: In the Testing Spring Boot Applications Masterclass, module 3 & 4 is entirely dedicated to test slicing. I walk through every slice Spring Boot offers, when to use each one, and how to refactor existing tests. You get decision trees, real examples, and templates you can copy.
Joyful testing,
Philip
Over the past few days, I've shown you the pain and cost of bad testing.
Now I want to show you how to fix it.
How I help teams ship with confidence
For the past 8 years, I've been helping Spring Boot teams go from deployment anxiety to shipping multiple times per day with confidence.The problems are always similar:
- Test suites that take 15-25 minutes
- Flaky tests that fail randomly
- Tests that don't catch real bugs
- Fear of making changes
The problem: @SpringBootTest everywhere
Here's what I see in almost every Spring Boot codebase I review:Every test class uses @SpringBootTest.
Every single test boots up the entire application - all the beans, all the auto-configuration, the database connections, the message queues, the security setup, everything.
For a modest application with 50 test classes, that's 50 complete application startups.
Each startup takes 10-15 seconds. 50 × 15 seconds = 12+ minutes just in application startup time.
The fix: Test slices
Spring Boot gives you test slices:- @WebMvcTest for controllers
- @DataJpaTest for repositories
- @JsonTest for JSON serialization
- @RestClientTest for REST clients
- And several others
Testing a REST controller? @WebMvcTest loads just the web layer - no database, no messaging, no full application context.
Testing a repository? @DataJpaTest loads just JPA and the database - no web layer, no full application context.
Real Results
Last year I worked with an e-commerce team. Their test suite took 18 minutes.We audited their 120 test classes:
- 95 were using @SpringBootTest
- Only 12 actually needed the full application context
- 83 could use test slices instead
- Test suite went from 18 minutes to 4 minutes
- Same tests, same coverage
- Zero functionality lost
18 minutes to 4 minutes with one technique.
When to use each slice
@WebMvcTest - Testing REST controllersLoads: Spring MVC, controllers, Jackson, validation
Doesn't load: Database, security (unless you want it), other layers
@DataJpaTest - Testing repositories
Loads: JPA, your repositories, an in-memory database
Doesn't load: Web layer, services, full application
@SpringBootTest - Integration tests only
Use this for tests that need the full application wired together
About 10-15% of your tests should use this
The Pattern
For a typical Spring Boot application:- 40% of tests: Test slices (@WebMvcTest, @DataJpaTest, etc.)
- 40% of tests: Unit tests with no Spring at all
- 10% of tests: @SpringBootTest for integration
Action Step
Open your codebase right now. Find one test class using @SpringBootTest that only tests a controller.Change @SpringBootTest to @WebMvcTest.
Add @MockBean for any dependencies the controller needs.
Run the test. Watch it go from 15 seconds to 2 seconds.
That feeling? That's the start of getting your time back.
Tomorrow, I'll show you technique #2: Spring TestContext Context caching. This is what takes you from minutes to seconds.
PS: In the Testing Spring Boot Applications Masterclass, module 3 & 4 is entirely dedicated to test slicing. I walk through every slice Spring Boot offers, when to use each one, and how to refactor existing tests. You get decision trees, real examples, and templates you can copy.
Joyful testing,
Philip
Copyright © 2026 PragmaTech Digital Solutions Philip Riecks, All rights reserved.
You are receiving this email because you opted in at our website https://rieckpil.de
Our mailing address is:
You are receiving this email because you opted in at our website https://rieckpil.de
Our mailing address is:
PragmaTech Digital Solutions Philip RiecksAdd us to your address book
Paul-Gossen-Straße 75
c/o Design Offices
Erlangen91052Germany
