一键导入
integration-test-patterns
Best practices for writing integration tests using Testcontainers and EF Core. Use when creating or modifying integration tests.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Best practices for writing integration tests using Testcontainers and EF Core. Use when creating or modifying integration tests.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Design system patterns for reusable UI via atomic design, Tailwind tokens/variants, and accessibility. Use when creating atoms/molecules, theming, or hardening a11y.
Entity Framework Core best practices for configuration, queries, concurrency, and multi-tenancy.
Frontend architecture patterns for React apps (React Router 7, TanStack Query). Use when planning features, defining routes, data strategies, and component gaps.
Infrastructure standards for Docker, scripts, middleware, and authentication in multi-tenant deployments.
Integration testing performance optimization, test parallelization, cleanup strategies, and CI/CD categorization patterns. Use when optimizing test execution speed, managing test data, or structuring tests for automated pipelines.
ASP.NET Core Minimal APIs patterns for endpoints, DTOs, validation, and service integration. Use when implementing API endpoints, defining request/response contracts, or structuring API projects with clean separation of concerns.
| name | integration-test-patterns |
| description | Best practices for writing integration tests using Testcontainers and EF Core. Use when creating or modifying integration tests. |
Use the DatabaseFixture to manage the SQL Server container lifecycle. This fixture is shared across tests to reduce overhead.
public class MyTests : IClassFixture<DatabaseFixture>
{
private readonly DatabaseFixture _fixture;
public MyTests(DatabaseFixture fixture)
{
_fixture = fixture;
}
}
Use the CreateDbContext helper pattern to create fresh contexts for Arrange and Act/Assert phases.
private static GloboTicketDbContext CreateDbContext(string connectionString, int? tenantId)
{
var options = new DbContextOptionsBuilder<GloboTicketDbContext>()
.UseSqlServer(connectionString, sqlOptions => sqlOptions.UseNetTopologySuite())
.Options;
var tenantContext = new TestTenantContext(tenantId);
var context = new GloboTicketDbContext(options, tenantContext);
context.Database.Migrate();
return context;
}
Always use a separate context for verifying data persistence to ensure EF Core didn't just return cached entities.
// Arrange
using (var setupContext = CreateDbContext(_fixture.ConnectionString, _tenantId))
{
// ... create data ...
}
// Act & Assert
using (var context = CreateDbContext(_fixture.ConnectionString, _tenantId))
{
// ... verify data ...
}
Use _fixture.GenerateRandomTenantId() and Guid.NewGuid() for properties like Slugs or Names to ensure tests do not collide in the shared container.
For guidance on test parallelization, cleanup strategies, and CI/CD organization, see Performance.