35

Is there a mocking framework for Azure similar to LocalStack for AWS? Please understand that I am not looking for a SDK mock but a resource stack mock.

So much so, that I could replace the configurations of my local Azure stack with actual Azure resources in my project and the functionality would remain just the same. Quite like how it works with Localstack.

I have found Azure Cloud Fabric to come closest to this, but it is tightly coupled with Visual Studio IDE.

Rajan Prasad
  • 1,582
  • 1
  • 16
  • 33
  • How do you use Azure Cloud Fabric for this? – Simon Woodside Mar 15 '19 at 19:05
  • 1
    @SimonWoodside, I read somewhere that Azure Cloud Fabric gives you a framework where you can call the Azure APIs for all their products as if you were actually using actual Azure resources. – Rajan Prasad Mar 17 '19 at 07:07
  • @RajanPrasad did you ever find a solution to this? I cant find anything similar to localstack either :( – Farhad-Taran Feb 06 '20 at 14:29
  • 1
    @farhad-taran, no brother. But I have made a castle in the air that I will build it and release it on Github. Let me see when I get time to build that castle in real world. – Rajan Prasad Feb 10 '20 at 03:26
  • 2
    There don't appear to be mocks available for many Azure services, for example I'm not aware of any local/mocks available for Azure Service Bus. Some services do have emulators, such as the [Azure Storage emulator](https://learn.microsoft.com/en-us/azure/storage/common/storage-use-emulator) and [Cosmos Db Emulator](https://learn.microsoft.com/en-us/azure/cosmos-db/local-emulator), which are released and supported by Microsoft. Some third party options also exist, such as [Azurite](https://github.com/Azure/Azurite). – Chris Feb 10 '20 at 09:46

2 Answers2

16

Although there is not an equivalent of LocalStack for Azure, Microsoft publish three emulators you can run locally to help with integration testing:

The above three can get you a lot of integration test coverage, however since Azure Functions, AWS Lambda and most modern web stacks even non-serverless have moved to consuming services rather than just consuming software modules, the only way to have complete parity between integration test and production environments is to automate the creation and tear-down of real, paid for services.

A recipe for End to End/Integration testing on Azure:

  • Use Azure DevOps Piplines to automate the entire CI process
  • Add tasks to the pipeline for creating and tearing down (real) text fixture resources with persistent state (databases, file storage etc) using the Azure command line tools.
  • Provide the test application access to real, stateless services (such as Azure Cognitive Services etc.) as you would for production.
  • Use Azure Variable Groups to store names, connection strings etc. for the test fixture resources. You can store a different set for production in a different group, allowing easy switching between them in YAML for different stages. These variables can also be templated in their own YAML file.
  • Use the Azure Functions Core Tools emulator to host and run functions within the CI agent rather than deploying, with a unit test framework giving them requests. The functions will be using the non-emulated, services stood up as test fixtures.
  • Or create a deploy for test stage, publishing the API for real, then write API tests that make raw HTTP requests, or use this as a backend for Selenium web driver testing a UI/frontend.

The above approach relies on real services to provide testing rather than emulated ones, testing something that's pretty close to what you deploy in production. It will incur usage fees each time you run your tests. If this is a problem, use unit testing and emulator integration testing first in the pipeline and add a human check/different pipeline for this level of testing which you only perform before pushing to production.

Azure Slots may also be worth looking up.

James
  • 30,496
  • 19
  • 86
  • 113
  • 3
    Well, I was looking mostly for something which can be used in development and testing without incurring costs to Azure. However, thanks for the tonnes of info that you have shared here. It will be really helpful when I get to using Azure. – Rajan Prasad Apr 19 '20 at 12:50
  • You're welcome. I've been looking to do the same thing, I would say that services with a consumption plan do only end up billing you for usage, which is very minimal when it comes to integration testing - so a run might only cost you a few pennies. – James Apr 19 '20 at 18:21
9

There is now https://github.com/azure/azurite providing also a docker https://hub.docker.com/_/microsoft-azure-storage-azurite

raphaelauv
  • 670
  • 1
  • 11
  • 22