I built a Spring Boot testing library to detect N+1 query problems
Hi everyone,
I’ve been working on an open-source testing library for detecting N+1 query problems in Spring Boot applications using Hibernate:
https://github.com/fabioformosa/n-plus-one-query-problem-detector
The idea is to catch N+1 regressions during integration tests, instead of discovering them later through slow endpoints or production monitoring.
The library currently supports two main approaches.
Scan mode can analyze an existing Spring integration test suite without requiring changes to individual tests. It monitors Hibernate statistics and repeated SQL patterns, then produces a report of possible N+1 candidates with different confidence levels.
You only need to enable it in your test configuration:
n-plus-one-query-detector.scan.enabled=true
n-plus-one-query-detector.scan.report.output=stdout
There is also an explicit assertion mode for tests where you want to enforce a query budget:
@SpringBootTest
@ExtendWith(NPlusOneQueryProblemDetectorExtension.class)
class CompanyServiceTest {
private CompanyService companyService;
@ExpectMaxQueries(1)
void listCompaniesWithoutNPlusOneQueries() {
companyService.list(0, 5);
}
}
The project supports Spring Boot 3.5.x and Spring Boot 4.x.
I’d be especially interested in feedback about:
- the scan-mode detection approach;
- possible false positives you encounter in real applications;
- the assertion API and developer experience;
- features that would make this useful in your CI pipeline.
The project is still evolving, so issues, suggestions and contributions are very welcome.
Posted Jul 14, 2026, 9:42 PM UTC