Skip to main content

Testcontainers Adapter

.NET only

The Testcontainers adapter is currently available for .NET (Xcepto.Testcontainers) only. Java users can use Testcontainers directly inside setupEnvironment() without a dedicated adapter.

The Testcontainers adapter integrates Testcontainers for .NET into the Xcepto scenario lifecycle. Containers started through it are automatically logged, monitored, and stopped during cleanup.

Install

<PackageReference Include="Xcepto.Testcontainers" Version="VERSION" />

Start a container in a scenario

Override Initialize and use ITestContainerSupport to start containers with integrated logging:

public class DatabaseScenario : XceptoScenario
{
public string ConnectionString { get; private set; }

protected override ScenarioInitialization Initialize(
ScenarioInitializationBuilder builder)
{
builder.Do(async provider =>
{
var support = provider
.GetRequiredService<ITestContainerSupport>();

var postgres = new PostgreSqlBuilder("postgres:18")
.WithDatabase("test")
.WithUsername("test")
.WithPassword("test")
.WithPortBinding(5432, true)
.WithWaitStrategy(
Wait.ForUnixContainer()
.UntilCommandIsCompleted(
"pg_isready -U test -d test"))
.WithOutputConsumer(
support.CreateOutputConsumer("postgres"))
.WithLogger(support.CreateLogger("postgres"))
.Build();

await postgres.StartAsync();

ConnectionString = postgres.GetConnectionString();
});

return builder.Build();
}
}

ITestContainerSupport

MethodPurpose
CreateOutputConsumer(name)Pipes container stdout/stderr into Xcepto's logging provider
CreateLogger(name)Returns an ILogger scoped to the named container

Using these methods ensures container output is captured and flushed alongside your test output — even when the test fails.

Using Testcontainers without the adapter (Java)

In xceptoj, start containers directly in setupEnvironment():

public class DatabaseScenario extends Scenario {
public String connectionString;
private PostgreSQLContainer<?> postgres;

@Override
public void setupEnvironment() throws XceptoScenarioResetException {
postgres = new PostgreSQLContainer<>("postgres:18")
.withDatabaseName("test")
.withUsername("test")
.withPassword("test");
postgres.start();
connectionString = postgres.getJdbcUrl();
}

@Override
public void stopEnvironment() throws XceptoScenarioResetException {
if (postgres != null) postgres.stop();
}
}