-
-
Notifications
You must be signed in to change notification settings - Fork 1
Testing Strategy
Language: English | Português (Brasil)
DbSqlLikeMem works best as the fast SQL-focused layer in your test strategy. It gives you realistic-enough SQL behavior for developer feedback, while a smaller set of real-provider tests still protects release-critical paths.
Use plain unit tests when the scenario does not need SQL at all.
Use DbSqlLikeMem when the scenario depends on SQL shape, seeded rows, transactions, savepoints, or provider-aware parsing, but does not need a running database server.
Keep a smaller suite against the real provider for engine-specific behavior, migration validation, production execution plans, and infrastructure-sensitive cases.
- Keep most day-to-day repository and service tests on DbSqlLikeMem for fast feedback.
- Add targeted provider-sensitive tests for dialect branches such as
RETURNING,OUTPUT, temporary tables, or provider-specific transaction behavior. - Keep end-to-end and release-gate scenarios on the real database engine.
Use DbMockConnectionFactory.Create*WithTables(...) when you want a short setup inside the test body.
var (db, connection) = DbMockConnectionFactory.CreateSqliteWithTables(
d => d.AddTable("Users",
[new Col("Id", DataTypeDef.Int32()), new Col("Name", DataTypeDef.String())],
[new Dictionary<int, object?> { [0] = 1, [1] = "Ana" }]));
connection.Open();When many tests share the same schema, promote that setup into a fixture or use schema snapshots so each test can start from a known structure with less boilerplate.
Use db.ResetVolatileData() when you want to keep table definitions but clear rows and reset identity state. Use connection.ResetAllVolatileData() when you also need to clear connection-scoped temporary state and invalidate savepoints.
Use interception for recording, logging, tracing, or resilience simulation. Keep the default test path simple unless the scenario needs extra observability.
- Use raw ADO.NET when you want maximum control over commands, readers, and transactions.
- Use Dapper when your production code already uses Dapper or when you want concise data access tests.
- Use the ORM and ecosystem packages when your application creates connections through EF Core, LinqToDB, or other higher-level adapters.
- Treating mock execution metrics as production performance benchmarks.
- Skipping provider selection and assuming SQL is identical across dialects.
- Rebuilding complex schemas in every test instead of using fixtures or snapshots.
- Replacing all real-provider tests instead of keeping a smaller final verification layer.
A good default is:
- write most SQL-facing repository tests with DbSqlLikeMem,
- keep provider-specific scenarios near the corresponding provider page,
- add interception only for diagnostics or resilience cases,
- keep a smaller real-database suite for final confidence.
- Home
- Getting Started
- DotNet Fiddle Quick Start
- Provider Selection
- Providers and Compatibility
- ADO.NET and Dapper
- DbConnection Interception
- DI and Interception Setup
- Testing Strategy
- Diagnostics and Execution Plans
- Limitations and Known Gaps
- Recipes and Common Scenarios
- Transactions and Volatile Data
- Schema Snapshots and Replay
- FAQ and Troubleshooting
- Observability and Debugging
- Benchmark Results
- Provider-Specific Recipes
- Examples by Architecture
- Migration from Real DB Tests
- Performance of Test Suites
- Compatibility Matrix Summary
- Glossary
- Extensions and Ecosystem
- ORM and Test Integrations
- MiniProfiler Integration
- Visual Studio Extension
- VS Code Extension
- Maintainer Resources
- Início
- Começando
- Começando no .NET Fiddle
- Escolha do Provider
- Provedores e Compatibilidade
- ADO.NET e Dapper
- Interceptação de DbConnection
- Setup de DI e Interceptação
- Estratégia de Testes
- Diagnóstico e Planos de Execução
- Limitações e Gaps Conhecidos
- Receitas e Cenários Comuns
- Transações e Dados Voláteis
- Snapshots de Schema e Replay
- FAQ e Troubleshooting