Azure Functions and Visual Studio enable the easy development and execution of C# code in the cloud. This course will teach you how to implement tests at different levels of granularity to ensure your Azure Functions work as expected.
Even though Azure Functions offer quick deployment of C# code to the cloud, it does not mean those functions should be published without first testing them. In this course, Testing Precompiled Azure Functions: Deep Dive, you'll learn how to write tests for your Azure Functions and workflows. First, you'll learn how to unit test core business logic and then how to test (and make testable) your function run methods. Next, you'll then discover how to use mocked function dependencies in your tests. Finally, you'll explore how to implement end to end function workflow tests. By the end of this course, you'll know how to ensure your Azure Functions are working as expected by implementing tests at different levels of granularity.
Course Overview Hi everyone. My name is Jason Roberts. Welcome to my course, Testing Precompiled Azure Functions: Deep Dive. I'm a Microsoft MVP, freelance developer, and author. In this course, we're going to learn how to create automated tests for your precompiled Azure functions. Some of the major topics that we'll cover in this course include how to test core business logic that's used in your functions, how to test function methods and deal with testability and dependency concerns, and how to create end-to-end tests for your function pipelines. By the end of this course, you'll understand how to create automated tests at different levels of granularity to ensure your Azure functions are working as expected. Before beginning the course, it's recommended that you have a basic understanding of C# and precompiled Azure functions. I hope you'll join me on this journey with the Testing Precompiled Azure Functions: Deep Dive course, at Pluralsight.
Getting Started Hi everyone. My name is Jason Roberts. Welcome to this course, Testing Precompiled Azure Functions: Deep Dive. Serverless computing and Azure functions enable the easy development and execution of C# code in the cloud. With Visual Studio, we can create function code in a familiar environment and take advantage of known tools and techniques. Just because it's easy to code and publish functions to the cloud, it does not mean that proven quality control techniques such as testing should be abandoned. No one likes to receive those phone calls in the middle of the night because a bug in the code is causing major problems. We're going to kick off this module with an overview of testing Azure functions and we'll learn how we can test at different levels such as testing the core business logic, testing the function Run methods themselves, and also testing the end-to-end or the function workflow. We'll learn about some of the potential challenges involved when testing Azure functions and we'll get an overview of the demo application we're going to be building in this course. We'll then head over to the Azure portal and we'll create our function app, and we'll also create the function and test projects in Visual Studio. Finally, we'll publish a test function to Azure just to check we've got everything set up as expected.
Isolating Function Code and Mocking Dependencies Hi. Welcome back. In the previous module, we wrote tests for our function run methods. In this module, we're going to see if we can improve the design of the function run methods to further isolate them for testing. So we're going to learn how we can isolate the function run methods from their dependencies and also provide mock versions of these dependencies in the test methods. So in this module, we're going to start off with an overview of testing function run methods in isolation, and ultimately, the aim of this is to give us the ability to provide mock versions of those dependencies if required, for example, the function dependencies may be hard to test or communicate with some third-party system, and in our test, we don't actually want to test these dependencies, we only want to test the function run logic itself. In this module, we're going to look at two ways to accomplish this. The first is a simple way where we create a public static property and we can set this from our unit test. And the second method is a little more involved this time injecting the dependencies into the function run method. The central refactoring that we need to make to support these scenarios is to take our LoanScorer class and extract an interface from it. We can then use this interface inside the function run method.
Implementing End to End Function Workflow Tests Hi. Welcome back. In the previous module, we learned how to isolate the function code and mock dependencies. In this module, we're going to be rounding out the course by learning how we can implement end-to-end function workflow tests. So up until this point in the course, the function code has been executing as part of tests inside Visual Studio. In this module, we're going to see how we can write tests that actually execute the functions within the function runtime itself. In this module, we're going to start off by getting an overview of end-to-end testing so we're going to look at some of the potential benefits of this style of testing, and also, some of the considerations to bear in mind. We'll then go and create a new end-to-end test class. This test class is going to perform a number of logical operations. First off, we're going to clear any existing blobs or queues from the test Azure storage location. Then we're going to start up the local function runtime. Once the runtime has started, we'll send the HTTP POST to our MakeApplication function and then we'll check the open-account blob container to check we have the correct result. Once we have this initial test working, we're going to go and refactor it. As part of this refactoring, we'll learn how to share the local function runtime instance between multiple tests so we don't have to spin up a new instance before every test method. We're going to be making use of xUnit. net's IClassFixture of T interface and we'll see how we can create multiple end-to-end test cases using the InlineData attribute. Finally, we'll wrap up this module in this course with some resources for further learning. So let's kick off this module by getting an overview of end-to-end testing.