Just because serverless allows us to quickly deploy value, it doesn’t mean that testing is now obsolete. (click to Tweet)
If we’re using Azure Functions as our serverless platform we can write our code (for example C#) and test it before deploying to Azure. In this case we’re talking about precompiled Azure Functions as opposed to earlier incarnations of Azure Functions that used .csx script files.
Working with precompiled functions means the code can be developed and tested on a local development machine. The code we write is familiar C# with some additional attributes to integrate the code with the Azure Functions runtime.
Because the code is just regular C#, we can use familiar testing tools such as MSTest, xUnit.net, or NUnit. Using these familiar testing frameworks it’s possible to write tests that operate at different levels of granularity.
One way to categorize these tests are into:
- Unit tests to check core business logic/value
- Integration tests to check function run methods are operating correctly
- End-to-end workflow tests that check multiple functions working together
To enable effective automated testing it may be necessary to write functions in such a way as to make them testable, for example by allowing function run method dependencies to be automatically injected at runtime, whereas at test time mock versions can be supplied for example using a framework such as AzureFunctions.Autofac.
There are other tools that allow us to more easily test functions locally such as the local functions runtime and the Azure storage emulator.
To learn more about using these tools and techniques to test Azure Functions, check out my Pluralsight course Testing Precompiled Azure Functions: Deep Dive.
You can start watching with a Pluralsight free trial.
SHARE: