docs/modules/azure.md
!!! note This module is INCUBATING. While it is ready for use and operational in the current version of Testcontainers, it is possible that it may receive breaking changes in the future. See our contributing guidelines for more information on our incubating modules policy.
Testcontainers module for the Microsoft Azure's SDK.
Currently, the module supports Azurite, Azure Event Hubs, Azure Service Bus and CosmosDB emulators. In order to use them, you should use the following classes:
| Class | Container Image |
|---|---|
| AzuriteContainer | mcr.microsoft.com/azure-storage/azurite |
| EventHubsEmulatorContainer | mcr.microsoft.com/azure-messaging/eventhubs-emulator |
| ServiceBusEmulatorContainer | mcr.microsoft.com/azure-messaging/servicebus-emulator |
| CosmosDBEmulatorContainer | mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator |
Start Azurite Emulator during a test:
<!--codeinclude-->Starting an Azurite container inside_block:emulatorContainer
<!--/codeinclude-->!!! note
SSL configuration is possible using the withSsl(MountableFile, String) and withSsl(MountableFile, MountableFile) methods.
If the tested application needs to use more than one set of credentials, the container can be configured to use custom credentials. Please see some examples below.
<!--codeinclude-->Starting an Azurite Blob container with one account and two keys inside_block:withTwoAccountKeys
<!--/codeinclude--> <!--codeinclude-->Starting an Azurite Blob container with more accounts and keys inside_block:withMoreAccounts
<!--/codeinclude-->Build Azure Blob client:
<!--codeinclude-->Build Azure Blob Service client inside_block:createBlobClient
<!--/codeinclude-->In case the application needs to use custom credentials, we can obtain them with a different method:
<!--codeinclude-->Obtain connection string with non-default credentials inside_block:useNonDefaultCredentials
<!--/codeinclude-->Build Azure Queue client:
<!--codeinclude-->Build Azure Queue Service client inside_block:createQueueClient
<!--/codeinclude-->!!! note We can use custom credentials the same way as defined in the Blob section.
Build Azure Table client:
<!--codeinclude-->Build Azure Table Service client inside_block:createTableClient
<!--/codeinclude-->!!! note We can use custom credentials the same way as defined in the Blob section.
Configuring the Azure Event Hubs Emulator container
<!--/codeinclude-->Start Azure Event Hubs Emulator during a test:
<!--codeinclude-->Setting up a network inside_block:network
<!--/codeinclude--> <!--codeinclude-->Starting an Azurite container as dependency inside_block:azuriteContainer
<!--/codeinclude--> <!--codeinclude-->Starting an Azure Event Hubs Emulator container inside_block:emulatorContainer
<!--/codeinclude-->Configure the consumer and the producer clients:
<!--codeinclude-->Configuring the clients inside_block:createProducerAndConsumer
<!--/codeinclude-->Configuring the Azure Service Bus Emulator container
<!--/codeinclude-->Start Azure Service Bus Emulator during a test:
<!--codeinclude-->Setting up a network inside_block:network
<!--/codeinclude--> <!--codeinclude-->Starting a SQL Server container as dependency inside_block:sqlContainer
<!--/codeinclude--> <!--codeinclude-->Starting a Service Bus Emulator container inside_block:emulatorContainer
<!--/codeinclude-->Configure the sender and the processor clients:
<!--codeinclude-->Configuring the sender client inside_block:senderClient
<!--/codeinclude--> <!--codeinclude-->Configuring the processor client inside_block:processorClient
<!--/codeinclude-->Start Azure CosmosDB Emulator during a test:
<!--codeinclude-->Starting an Azure CosmosDB Emulator container inside_block:emulatorContainer
<!--/codeinclude-->Prepare KeyStore to use for SSL.
<!--codeinclude-->Building KeyStore from certificate within container inside_block:buildAndSaveNewKeyStore
<!--/codeinclude-->Set system trust-store parameters to use already built KeyStore:
<!--codeinclude-->Set system trust-store parameters inside_block:setSystemTrustStoreParameters
<!--/codeinclude-->Build Azure CosmosDB client:
<!--codeinclude-->Build Azure CosmosDB client inside_block:buildClient
<!--/codeinclude-->Test against the Emulator:
<!--codeinclude-->Testing against Azure CosmosDB Emulator container inside_block:testWithClientAgainstEmulatorContainer
<!--/codeinclude-->Add the following dependency to your pom.xml/build.gradle file:
=== "Gradle"
groovy testImplementation "org.testcontainers:testcontainers-azure:{{latest_version}}"
=== "Maven"
xml <dependency> <groupId>org.testcontainers</groupId> <artifactId>testcontainers-azure</artifactId> <version>{{latest_version}}</version> <scope>test</scope> </dependency>