スキル一覧に戻る
michaellperry

integration-test-patterns

by michaellperry

0🍴 0📅 2026年1月23日
GitHubで見るManusで実行

SKILL.md


name: integration-test-patterns description: Best practices for writing integration tests using Testcontainers and EF Core. Use when creating or modifying integration tests.

Integration Test Patterns

Infrastructure

DatabaseFixture

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;
    }
}

Context Management

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;
}

Test Structure

Fresh Context Pattern

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 ...
}

Isolation

Use _fixture.GenerateRandomTenantId() and Guid.NewGuid() for properties like Slugs or Names to ensure tests do not collide in the shared container.

Performance and Execution

For guidance on test parallelization, cleanup strategies, and CI/CD organization, see Performance.

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です