Does it make sense to use an Azure Function to run integration tests?

Claus Appel 1 Reputation point
2022-01-20T12:42:00.05+00:00

Important 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.

Does this seem sane? Can I get any standard test runner (e.g. dotnet test) to run from an Azure Function? Is that reasonably practical, or does it sound like 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.

Thanks a lot in advance!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,291 questions
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
329 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,421 Reputation points
    2022-01-20T14:35:22.847+00:00

    @Claus Appel ,

    Thanks for reaching out to Q&A.

    Yes. You can run c# based unit tests in Azure functions using Xunit : https://learn.microsoft.com/en-us/azure/azure-functions/functions-test-a-function

    Functions engineering team is working on providing a complete test framework that can be run on Functions. There is no ETA on it though, you can follow up here : https://github.com/Azure/azure-functions-dotnet-worker/issues/281

    You can explore the above mentioned approach. Also the source controls and pipelines that you have as alternatives are supported in functions.

    I hope this helps! Feel free to reach out to me if you have any queries or concerns.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


  2. sadomovalex 3,626 Reputation points
    2022-01-24T15:07:34.407+00:00

    do you want to run exactly integration test (e.g. test that transport layer to your Azure functions (AF) works) or want to test logic implemented inside Azure functions? I'm asking because AF project is similar to regular Class library (so you may reference it e.g. in Unit test project and write tests over AF logic there without making actual calls to running AF) so you may move code with logic to helper classes and just call these classes from AF. Then in Unit test project you will only test these helper classes:

    Azure function (e.g. with http binding) -> calls MyHelper.Foo()
    Test case -> tests MyHelper.Foo() (not Azure function itself)

    0 comments No comments