In my previous post, I looked into running API tests and automate them. For this, I stumbled upon Insomnia and Loadmill. This time, I want to integrate these tests into my CI/CD pipeline as easily as possible.

Let’s depart and check out some possibilities.

Framework specific tools

ASP.NET Core has a test server extension (it’s called TestServer) by Microsoft, a dependency that neatly integrates into ASP.NET Core and exposes an in-memory web host. In addition to that, it also provides a pre-configured HTTP client that we can use.

This extension does also integrates well into test frameworks like xUnit or NUnit. That sounds interesting enough so let’s give it a shot without overwhelming you too much.

Let’s take my work in progress homepage API again as a sample. For now, I maintain a simple project structure with a single API controller in it.

(yes I know, Homepage.API sounds generic & boring so I rolled with this name instead)

In my next step, I create a simple test project powered by xUnit, pull the test host dependency ( dotnet add Microsoft.AspNetCore.TestHost ), reference my API project, and modify the default test class to something like this:

And our test method looks like this:

This goes without saying, but you can run this integration test in any CI/CD environment. Visual Studio can also run tests while you are developing (‘live tests’). It sounds like a great way to ensure that your code’s quality is on a high bar next to your typical unit and integration tests. Pretty cool.

This method is a bit farther away from production because it runs in in-memory, but it helps you to test with confidence in development and staging. Not bad.

In the realms of CI/CD

Since I utilize Loadmill for evaluation purposes lately, I thought I’d continue this path and see how we can use it in this scenario. I stumbled upon their official npm package for CI which looks promising. In my case, I’m using Azure DevOps, but this works with any other CI tool.

Loadmill’s npm package allows you to run a pre-configured Test Suite from remote. I have an existing Azure Pipelines definition that releases the new build to my server. Let’s modify this definition so it can also run the npm package with the same test suite I created last time.

For this, we create a new stage that depends on the release stage.