Dec 6–8, 2022San Francisco

Sessions

How Fixing a Broken Window Cut Down Our Build Time by 50%

Track: Intermediate/Advanced Spring

The broken windows (not the operating system 😀) theory not only applies to criminological cases but also codebases. It only takes one lazy developer to break the first window. Chances are high that others will follow a similar path and take workarounds or reapply a not-so-optimal pattern thinking, “It passed the code review, I must not be that bad.”

For our Spring Boot integration test setup, we had such a broken window that was causing ever-growing build times. While most books about clean architecture emphasize composition over inheritance, we drifted off from this rule and coupled our tests to an AbstractIntegrationTest class that we then annotated with @DirtiesContext.

This resulted in ever-growing build times as each new integration test was launching its own Spring TestContext, adding valuable seconds to the overall build time. Our feedback cycles, as well as the overall satisfaction of the team, started to suffer from this.

This talk describes our journey of getting rid of @DirtiesContext on top of an abstract test class (aka, the "broken window") that made reusing the Spring TestContext impossible and resulted in ever-growing build times. Furthermore, we’ll discuss recipes, best practices, and antipatterns for reusing the Spring TestContext and testing Spring Boot applications in general.

After fixing this "broken window," our overall build time went down by 50% from 25 to 12 minutes.