Adding Automated Tests to a Serverless Application

Learn how to add automated integration tests to a serverless application project.

Unit vs. integration tests

If we use a hosted ASP.NET Core web application as a serverless AWS Lambda application, we can run the same types of automated tests as we can for any standard ASP.NET Core application. Any business logic can be tested via standard unit tests. However, we can also test the endpoints using an integration test host provided by ASP.NET Core.

Here are the key differences between unit tests and integration tests.

  • Unit tests are designed to test a unit of functionality. They don’t rely on the application being hosted, and they call methods directly.

  • Integration tests rely on the application being hosted, even if it’s a local test host. They trigger the application via its endpoints, not by calling the methods directly.

Note: Even though the application needs to be hosted for integration tests, it doesn’t have to be fully deployed. In the context of integration tests, hosting can be done just for the duration of the tests. Also, we only need to map the application endpoints to appropriate network ports; we might not have to host the entire application.

So far, the tests we’ve covered have been classed as unit tests. In this lesson, we’ll follow the process of writing integration tests for a serverless AWS Lambda application. This playground shows us how.

Get hands-on with 1200+ tech skills courses.