The problem
An integration test can pass while quietly issuing ten times the queries it used to - an N+1 that crept in, an index that got dropped, a fetch join that stopped working. Nothing fails, nothing warns; the regression just ships. Parsing Hibernate's SQL logs to catch this is fragile and framework-specific.
What it does
Captures
Wraps the DataSource at the JDBC layer, so every statement is recorded regardless of
whether it came from Spring Data JPA, Hibernate, JdbcTemplate, or plain JDBC.
Asserts
A fluent assertThatQueries() AssertJ DSL for counts, tables, duplicates, and N+1
detection, plus PostgreSQL EXPLAIN-backed index assertions.
Stays out of the way
Test-scoped dependencies, automatic DataSource wrapping under Spring Boot, no
annotation processor.
Usage
Add the dependencies (see latest release for the version):
<dependency>
<groupId>li.selman</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>VERSION</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>li.selman</groupId>
<artifactId>query-assertions</artifactId>
<version>VERSION</version>
<scope>test</scope>
</dependency>
@SpringBootTest
class OrderRepositoryTest {
@Autowired
private OrderRepository orderRepository;
@Test
void findsOrdersByCustomerWithoutNPlusOne() {
orderRepository.findByCustomerId(customerId);
assertThatQueries().selects(1).containsNoDelete().hasNoNPlusOne();
}
}
No manual DataSource wrapping and no @ExtendWith needed - the DataSource
bean is wrapped automatically, and capture state resets before every test method. Full module breakdown,
including hibernate-support, snapshot-testing, and plan-assertions,
is in the README.
Modules
| Module | Purpose |
|---|---|
persistence-test-core | Domain model + SQL normalization, no framework dependencies. |
query-capture | JDBC-layer capture via datasource-proxy. |
query-analysis | Statistics, duplicate/N+1 detection. |
query-assertions | The assertThatQueries() AssertJ DSL. |
hibernate-support | Entity-aware assertions (optional Hibernate dependency). |
snapshot-testing | Deterministic query snapshots via java-snapshot-testing. |
spring-boot-autoconfigure | Automatic DataSource wrapping + test wiring. |
plan-assertions | PostgreSQL EXPLAIN-backed index/scan assertions. |