Mocking feature in Azure Functions
  • 09 Sep 2022
  • 1 Minute to read
  • Contributors
  • Comment
  • Dark
    Light
  • PDF

Mocking feature in Azure Functions

  • Comment
  • Dark
    Light
  • PDF

#ServerlessTips - Azure Functions
Author: Steef-Jan Wiggers Azure MVP

An essential aspect of developing code is testing. Your code needs to be robust and able to perform.

You can test your function behaviour by using the mocking feature provided through Azure Function Proxies.

In the Azure portal, you navigate to your Function App and select a function. Click proxies in the chosen function and create a new proxy. Next, you provide a name, route template, allowed HTTP methods, and for example choose to override the response when the function is invoked.
Tip 20- Mocking and Azure Functions Pic 1.png

Once you have created the proxy, you will see proxy URL you can call with for instance Postman.
Tip 20- Mocking and Azure Functions Pic 2.png

By calling the URL with any payload, you will see the 200 response is returned.
Tip 20- Mocking and Azure Functions Pic 3.png

Using proxies is a way to mock your HTTP-triggered Azure Functions. The process of creating proxies is straight forward and can be easily be incorporated in a CI/CD pipeline (see Azure Function Proxies for API Mocking). Furthermore, you can create multiple proxies to test various functions in your Function App.

Lastly, you can apply to mock for durable functions. According to the Microsoft docs mocking is supported – see Unit testing for Durable Functions.

Azure-functions.png


Was this article helpful?