Skip to content
Jonathan George By Jonathan George Software Engineer IV
Integration Testing Azure Functions with SpecFlow and C#, Part 4 - Controlling your functions with additional configuration

TL;DR - This series of posts shows how you can integration test Azure Functions projects using the open-source Corvus.Testing library and walks through the different ways you can use it in your SpecFlow projects to start and stop function app instances for your scenarios and features.

In the previous posts in this series, we introduced the Corvus.Testing project and showed how you can use the bindings and classes it provides to start functions apps as part of your scenarios and features. Here, we look at how you can vary the behaviour of those functions apps by providing or overriding configuration values.

When the FunctionsController is used to start a new function, it will check the ScenarioContext (if available) and FeatureContext for an instance of the FunctionConfiguration class. Any configuration provided here will be made available to the functions app when it starts.

If you're using step bindings to start your function, you can do this by writing an additional step binding to provide configuration from wherever you need to retrieve it. Note that this step must come before the one that starts the function. You can see an example in ScenariosUsingStepBindings.feature:

If you're using a BeforeScenario or BeforeFeature hook, you can add the configuration at the same time - as shown in ScenariosUsingPerScenarioHookWithAdditionalConfiguration.feature (and the corresponding hook method in DemoFunctionPerScenario, StartFunctionWithAdditionalConfigurationAsync, as well as the per-feature equivalents.

If you need to use different configuration at different times, you can create separate hook methods for setting up configuration - just ensure you use the Order parameter on the hook attributes to ensure the configuration is set prior to the functions being started.

In the next (and final) post in the series, we'll cover how to ensure the tests you've written using the techniques covered in these posts can run in your build pipelines.

Azure Weekly is a summary of the week's top Microsoft Azure news from AI to Availability Zones. Keep on top of all the latest Azure developments!

Jonathan George

Software Engineer IV

Jonathan George

Jon is an experienced project lead and architect who has spent nearly 20 years delivering industry-leading solutions for clients across multiple industries including oil and gas, retail, financial services and healthcare. At endjin, he helps clients take advantage of the huge opportunities presented by cloud technologies to better understand and grow their businesses.