Asserting EF Core query counts in integration tests — catching N+1 regressions #1608
KiwiDevelopment
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This template ships with a great integration test setup — WebApplicationFactory, real database, proper test isolation. One thing I kept adding manually on top of it was a way to assert how many SQL queries an endpoint actually fires.
The problem: you can have a perfectly passing test that validates the response body, but the endpoint quietly fires 50 queries instead of 1. No test catches it until production.
I built a small library for this: KiwiQuery.EFCore.
It wraps DbCommandInterceptor into a single method call — no boilerplate. Works with whatever database you're using in tests.
Repo: https://github.com/KiwiDevelopment/KiwiQuery, NuGet: KiwiQuery.EFCore. MIT, one dependency.
Curious if others in this community handle query count assertions differently, or if this pattern is useful for the template itself.
Beta Was this translation helpful? Give feedback.
All reactions