5

What is the best way to test AzureFunctions [C#, HTTP trigger] in local environment, using VisualStudio and XUnit?

Lets assume that I have following two Azure Functions:

  1. AF1: Parse JSON input and store to database
  2. AF2: Generate XML file from data uploaded to database

I would like to test them in following manner:

  1. Prepare a JSON and sent to first Azure Function by HTTP request
  2. Azure function returns documentId in HTTP response
  3. Send documentId to second AzureFunction by HTTP request
  4. Test the output XML

Is it possible to run those two AzureFunction simultaneously from XUnit environment ? How to achieve that? I don't want to test the .dll with Azure Function itself, I would like to test it using HTTP requests.

Szymon Tomczyk
  • 1,219
  • 11
  • 16
  • 2
    Nor sure if this is what you were referring to https://blogs.msdn.microsoft.com/visualstudioalmrangers/2017/09/24/azure-function-integration-tests-automation/ – Nkosi Dec 02 '18 at 11:50
  • 1
    Here is another useful link https://learn.microsoft.com/en-us/azure/azure-functions/functions-test-a-function – Nkosi Dec 02 '18 at 11:52
  • Thank you @Nkosi, I've seen both of those links. I would like to test them on local environment instead of Azure, but I don't know how to run mutliple Azure Functions locally. – Szymon Tomczyk Dec 02 '18 at 11:59
  • 1
    Here is a link to run multiple Azure Function apps locally - https://github.com/Azure/azure-functions-core-tools/issues/310 Added the following as 'Application arguments' to one of the AF app - 'host start --pause-on-error --nodeDebugPort 5859' and specified the following in the local.settings.json - "Host": { "LocalHttpPort" : 7072 } To run them all from code you might have to start the 2 apps ('func.exe' ) in 2 processes and make an http call from your test code. – alwayslearning Dec 03 '18 at 12:40

1 Answers1

0

I had a similar scenario where i had to run, two Azure Function projects locally for debugging. The fix is to add the command line switch --nodeDebugPort 5859 to your launching of function host to set the port for one of the sessions.

There is an issue tracked here as well as my question here

HariHaran
  • 3,642
  • 2
  • 16
  • 33