Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Testing Azure Functions and .csx Files

Azure Functions abstract plenty of dependencies like queue libraries and Azure Tables. So from a Unit Test dependencies mocking perspective, there is less coding effort (and accordingly less maintenance).

Assuming we are developing locally using Visual Studio 2015

  • How can I unit test (not interested in integration test) a single Azure Function? Preferably in xUnit, however, any framework would do.
  • How can I unit test a function in a .csx file in general?
like image 365
Adam Avatar asked Feb 28 '17 16:02

Adam


People also ask

Can you unit test Azure functions?

When executing your Azure Functions, the functions runtime will run your function code with a concrete implementation of these interfaces. For unit testing, you can pass in a mocked version of these interfaces to test your business logic.

Which library allows you to develop and test Azure functions locally before deploying into Azure?

Azure Functions Core Tools provides the core runtime and templates for creating functions, which enable local development.

Can we write Azure functions in VS code?

Visual Studio Code integrates with Azure Functions Core tools to let you run this project on your local development computer before you publish to Azure. To call your function, press F5 to start the function app project. The Terminal panel displays the output from Core Tools.


1 Answers

As it stands, it's not really possible to unit test those files. For that reason (and a number of others), we have switched to a different model when developing Functions from Visual Studio, based on .cs and more standard .NET libraries. This makes a lot of things more 'normal' in Visual Studio. See doc for details.

Update: see also Could not load file or assembly System.Net.Http, Version=4.1.1.0 in Unit Test for Azure Functions relating to unit test projects.

like image 56
David Ebbo Avatar answered Nov 12 '22 11:11

David Ebbo