Scheduled upgrade in progress. Some pages may load slowly or ask you to retry.

DB Test

Generate database integration tests with Testcontainers

majiayu000 da61202 2 files · 1.9 KB Updated 567 repo stars

File contents

Database Integration Tests

Generate integration tests using Testcontainers for real database validation.

For .NET (Testcontainers)

dotnet add package Testcontainers.CosmosDb
public class CandidateRepositoryTests : IAsyncLifetime
{
    private readonly CosmosDbContainer _container = new CosmosDbBuilder().Build();

    public async Task InitializeAsync() => await _container.StartAsync();
    public async Task DisposeAsync() => await _container.DisposeAsync();

    [Fact]
    public async Task Create_ValidCandidate_Persists()
    {
        var client = new CosmosClient(_container.GetConnectionString());
        var repo = new CandidateRepository(client, Options.Create(settings));
        var candidate = CreateTestCandidate();
        await repo.CreateAsync(candidate);
        var result = await repo.GetByIdAsync(candidate.Id);
        result.Should().BeEquivalentTo(candidate);
    }
}

Arguments

  • <repository-name>: Repository class to test
  • --provider=<cosmosdb|postgres|mongodb>: Database provider

majiayu000/claude-skill-registry-data/tree/main/testing/db-test commit da6120200d

Frequently asked questions

npx skillmds add majiayu000/db-test