Search code examples
azure-functionsintegration-testing

Can I use an Azure Function to run unit/integration tests? How?


Background

Disambiguation: Here I am NOT trying to test my Azure Function. Rather, I am investigating the possiblity of using an Azure Function to test my other code.

I am developing an Azure web application in C#. I want to have really good coverage of unit and integration tests (aka end-to-end-tests). We use Jenkins as our main continuous integration tool. We have a suite of tests that runs on each Jenkins push. We have the following conflict of interests:

  • We want our mandatory Jenkins test suite to be reasonably fast (a few minutes).
  • We want to have automated tests of a number of complex scenarios that can be quite long-running (potentially many minutes).

So I am investigating how to auto-run our long-running tests somewhere other than our regular Jenkins pipeline.

Since we need Azure anyway, I have looked into having an Azure Function run some of our tests. It would run every evening and would need to get the newest code (either take it from GitHub, or our regular Jenkins job could put the code as an artifact somewhere else where the test runner can get it) and run the tests.

Actual question

Can I get any standard test runner (e.g. dotnet test) to run from an Azure Function? Is that reasonably practical? If so, how can I do it?

It is possible that this is a bad idea. I am a novice to Azure Functions, so I don't know how difficult this would be.

Alternatives might be:

  • A separate Jenkins pipeline.
  • GitHub Actions.
  • Azure DevOps.
  • Azure container apps (which I have not looked into at all).

We are using C#, .NET 5.0+ and ASP.Net Core. Our tests currently use xUnit, but that part is negotiable.

Again, my core question is: Is it possible - and reasonably convenient - to get an Azure Function to run a suite of tests? Or should I bark up a completely different tree?

Thanks a lot in advance!


Solution

  • After asking around I ended up NOT using an Azure function for this. I am now using a GitHub Action instead, which seems a much better fit.