← Back to blog
27 October 2021 · 7 min read

Azure Storage Integration Testing with Azurite

If you depend on Azure Storage, you need a solution to Integration Test in a local development environment.

We live in a world where we rely more on Cloud offers, using proprietary managed solutions. One of those examples is Azure Storage (Blobs, Queues, and Tables).

One of the problems with relying on those kinds of offerings is how to have an environment disconnected from Azure to run your code while testing or developing.

Ideally, we want to have a solution to run it in an offline environment. That can give us the following benefits:

An excellent solution to that in the case of Azure Storage is Azurite.

What is Azurite?

Azurite is an open-source Azure Storage emulator that provides a cross-platform experience in a local environment. Azurite simulates most of the commands supported by Azure Storage with minimal dependencies.

How to use it?

Azurite is a Node.js application, so you can npm install it and use it from the command line (see here).

But, I prefer to use docker containers, and it's that what we will see here.

First, create a docker-compose.yml like the following.

version: "3.9"
services:
  azurite:
    image: mcr.microsoft.com/azure-storage/azurite
    hostname: azurite
    restart: always
    ports:
      - "10000:10000"
      - "10001:10001"
      - "10002:10002"

Azurite will listen to 10000 as Blob service port, 10001 as Queue service port, and 10002 as the Table service port. Configure the ones you need.

After that, just run your docker-compose up and you will be able to connect to it.

var connectionString = "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;";
var account = CloudStorageAccount.Parse(connectionString);
var client = account.CreateCloudTableClient();

Hope that this was useful! To get more tips like this, follow me on Twitter (@gsferreira) and let's keep in touch!

Developer Insights

What I'm building, learning, and discovering each week.

By signing up, you'll get my free weekly newsletter plus occasional updates about my courses. You can unsubscribe anytime.