Hi, I landed in the project by looking at this issue to support Testcontainers for component tests.
I currently see this is how resources are provisioned:
For Redis container:
builder.AddRedis("basketcache")
.WithDataVolume()
.WithRedisCommander();
For Azure Redis:
builder.AddRedis("cache").AsAzureRedis()
Proposal
Provide an API to provide specific Resource definitions, let's say AspireResource. For the Redis example, it can use AzureRedisExtensions or Testcontainers Redis module. The API can be also used in case there are other ways to provision a Redis instance, so, developers can write their own implementation.
For Testcontainers Redis:
var redisContainer = new RedisBuilder()
.WithImage("redis:7.0")
.Build();
builder.AddRedis("cache", new TestcontainersAspireResource().WithContainer(redisContainer).Build()))
where TestcontainersAspireResource will start the container.
For Azure Redis:
builder.AddRedis("cache", new AzureAspireResource().WithExtension(new AzureRedisExtension()).Build())
Benefits
- Unify the experience for dev and test by using the same API to provide resources
- Generic API to define and start a container
- Support Docker network
- Integrates with Testcontainers Desktop
- Docker socket auto-detection
- Automatic resource cleanup
- Recently, reuse containers feature was added. So, the same instance can be shared cross-services
Also, by looking at the issues, some of them are already handled by Testcontainers. For example:
All Testcontainers .NET are listed in the module catalog.
If there is no specific module the Testcontainers API is very fluent and allow the user to write their own definition.
var container = new ContainerBuilder()
.WithImage("testcontainers/helloworld:1.1.0")
.WithPortBinding(8080, true)
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(8080)))
.Build();
await container.StartAsync()
.ConfigureAwait(false);
References
In the Java world, this integration has been done in the three major frameworks (Quarkus devservices, Micronaut test-resources, Spring Boot service connection). I would be very happy to chat and share more about it in order to find a similar experience in .NET ecosystem with Aspire.
Hi, I landed in the project by looking at this issue to support Testcontainers for component tests.
I currently see this is how resources are provisioned:
For Redis container:
For Azure Redis:
Proposal
Provide an API to provide specific Resource definitions, let's say
AspireResource. For the Redis example, it can use AzureRedisExtensions or Testcontainers Redis module. The API can be also used in case there are other ways to provision a Redis instance, so, developers can write their own implementation.For Testcontainers Redis:
where
TestcontainersAspireResourcewill start the container.For Azure Redis:
Benefits
Also, by looking at the issues, some of them are already handled by Testcontainers. For example:
PGvector is compatible with current Testcontainers PostgreSQL implementation. For more info can look at the module https://testcontainers.com/modules/pgvector/
Ryuk is Testcontainers resource reaper, which is in charge of cleanup resources when the process is done.
Keycloack also has a Testcontainers implementation https://testcontainers.com/modules/keycloak/
Use RabbitMQ module with reuse functionality could help https://testcontainers.com/modules/rabbitmq/
By using the Generic API users can enable it without waiting for this feature
All Testcontainers .NET are listed in the module catalog.
If there is no specific module the Testcontainers API is very fluent and allow the user to write their own definition.
References
In the Java world, this integration has been done in the three major frameworks (Quarkus devservices, Micronaut test-resources, Spring Boot service connection). I would be very happy to chat and share more about it in order to find a similar experience in .NET ecosystem with Aspire.