Situation
The 8-year-old core SaaS monolith contained over 5,000 integration tests written without strict layering. Over 40% of tests performed full database mutations and heavy file I/O operations to validate simple business logic rules, leading to an unsustainable 18% global flakiness rate and continuous pipeline blockages.
Task
Decompose and refactor the legacy test suite into a strict testing pyramid, decoupling unit logic from external database dependencies while establishing automated code quality gates in CI.
Action
- Automated Flakiness Quarantining: Built a custom JUnit listener that auto-detected tests failing more than once in 10 runs, automatically annotating them with
@Flakyand quarantining them out of PR-blocking pipelines into a non-blocking diagnostic queue. - Service-Layer Mocking Modernization: Replaced direct database calls in core domain verification tests with isolated
Mockitocontext mocks, decoupling business logic checks from underlying relational schemas. - Static Analysis Quality Gates: Configured SonarQube rules inside Jenkins to fail builds if a new PR introduced thread-unsafe static variables or direct
Thread.sleep()calls inside test methods.
Result
- Dropped global pipeline flakiness from 18% to under 0.5%.
- Reduced total build execution time from 90 minutes to 31 minutes, saving hundreds of monthly developer waiting hours.