| name | dotnet-testing-advanced-testcontainers-database |
| category | testing |
| subcategory | integration |
| description | Specialized skill for containerized database testing using Testcontainers. Use when testing real database behavior, using SQL Server/PostgreSQL/MySQL containers, testing EF Core/Dapper. Covers container startup, database migrations, test isolation, container sharing.
Keywords: testcontainers, container testing, database testing, MsSqlContainer, PostgreSqlContainer, MySqlContainer, EF Core testing, Dapper testing, Testcontainers.MsSql, Testcontainers.PostgreSql, GetConnectionString, IAsyncLifetime, CollectionFixture
|
| targets | ["*"] |
| license | MIT |
| metadata | {"author":"Kevin Tseng","version":"1.0.0","tags":".NET, testing, Testcontainers, database, SQL Server, PostgreSQL","related_skills":"advanced-testcontainers-nosql, advanced-aspnet-integration-testing, advanced-aspire-testing"} |
| claudecode | {} |
| opencode | {} |
| codexcli | {"short-description":".NET skill guidance for dotnet-testing-advanced-testcontainers-database"} |
| copilot | {} |
| geminicli | {} |
| antigravity | {} |
Source: kevintsengtw/dotnet-testing-agent-skills (MIT). Ported into dotnet-agent-harness.
Testcontainers Database Integration Testing Guide
Applicable Scenarios
Use this skill when asked to perform the following tasks:
- Need to test real database behavior (transactions, concurrency, stored procedures, etc.)
- EF Core InMemory database cannot meet testing requirements
- Create containerized testing environment for PostgreSQL or MSSQL
- Use Collection Fixture pattern to share container instances
- Test data access layer for both EF Core and Dapper
- Need SQL script externalization strategy
EF Core InMemory Limitations
Before choosing a testing strategy, must understand the significant limitations of EF Core InMemory database:
1. Transaction Behavior and Database Locking
- Does not support database transactions:
SaveChanges() immediately saves data, cannot Rollback
- No database locking mechanism: Cannot simulate behavior under concurrency scenarios
2. LINQ Query Differences
- Query translation differences: Some LINQ queries (complex GroupBy, JOIN, custom functions) work in InMemory but
may fail when translated to SQL
- Case Sensitivity: InMemory defaults to case-insensitive, but real databases depend on collation rules
- Performance simulation insufficient: Cannot simulate real database performance bottlenecks or index issues
3. Database-Specific Features
InMemory mode cannot test:
- Stored Procedures and Triggers
- Views
- Foreign Key Constraints, Check Constraints
- Data type precision (decimal, datetime, etc.)
- Concurrency Tokens (RowVersion, Timestamp)
Conclusion: When needing to validate complex transaction logic, concurrency handling, or database-specific behavior,
should use Testcontainers for integration testing.
Testcontainers Core Concepts
What is Testcontainers?
Testcontainers is a testing library providing lightweight, easy-to-use API to start Docker containers, specifically for
integration testing.
Core Advantages
- Real Environment Testing: Use real databases, test actual SQL syntax and database constraints
- Environment Consistency: Ensure test environment uses same service versions as production
- Clean Test Environment: Each test has independent clean environment, containers auto-cleanup