Asserting EF Core query counts in integration tests — catching N+1 regressions #1013
KiwiDevelopment
started this conversation in
Ideas
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Steve, you've written a lot about testing best practices in Clean Architecture. One pattern I haven't seen discussed much in the .NET world is asserting the number of SQL queries an endpoint fires — not just the result.
Django has had assertNumQueries built-in since 2011. In .NET there's no equivalent, so every team either ignores it or writes their own DbCommandInterceptor boilerplate.
I built KiwiQuery.EFCore to fill that gap:
The idea: add one assertion per critical endpoint, and N+1 regressions get caught in CI before they hit production.
Repo: https://github.com/KiwiDevelopment/KiwiQuery, NuGet: KiwiQuery.EFCore. MIT, one dependency.
Do you think this pattern deserves a place in Clean Architecture templates? Curious to hear your take.
Beta Was this translation helpful? Give feedback.
All reactions