Azure-docs: How can we test the App with dependency injection?

Created on 19 Jul 2019  Â·  4Comments  Â·  Source: MicrosoftDocs/azure-docs

Hi,

I've been impressed with the ASP.NET Integration Tests which allow you to have a web server in memory to test against. I was wondering if it is possible that something like that exists here?

I'm hoping for the ability to create an instance of the function (maybe from a factory so singletons can be re-used) and then triggering the function somehow, maybe by sending http requests to the function app similar to the ability to locally send http requests to functions that are not http triggered functions.

I want to test the dependency injection loads my function properly, as well as the function working as intended. I'm not too bothered about testing it on the infrastructure (like deploying it and seeing if it works).

Thanks
Chris


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri1 azure-functionsvc cxp product-question triaged

Most helpful comment

We do this today internally: https://github.com/Azure/azure-functions-host/blob/dev/test/WebJobs.Script.Tests.Integration/TestFunctionHost.cs.

@jeffhollan took this and broke it out into a separate repo here: https://github.com/jeffhollan/functions-test-helper. But I'm not sure that this has been kept up-to-date and may not function exactly like our host.

Internally we've talked about releasing and maintaining this, but it hasn't happened yet. I've gone ahead and created an issue to track this. https://github.com/Azure/azure-functions-host/issues/4862

In the meantime, your best bet is to use Jeff's repo or our internal one as a guide to get this set up yourself.

All 4 comments

Hi @chris31389 - Thank you for your feedback! We will review and update as appropriate.

@mike-urnun-msft Hi, have you managed to have a look at this request?

We do this today internally: https://github.com/Azure/azure-functions-host/blob/dev/test/WebJobs.Script.Tests.Integration/TestFunctionHost.cs.

@jeffhollan took this and broke it out into a separate repo here: https://github.com/jeffhollan/functions-test-helper. But I'm not sure that this has been kept up-to-date and may not function exactly like our host.

Internally we've talked about releasing and maintaining this, but it hasn't happened yet. I've gone ahead and created an issue to track this. https://github.com/Azure/azure-functions-host/issues/4862

In the meantime, your best bet is to use Jeff's repo or our internal one as a guide to get this set up yourself.

Thanks @brettsam! We will now proceed to close this thread. If there are further questions regarding this matter, please refer to the resources that Brett shared above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JeffLoo-ong picture JeffLoo-ong  Â·  3Comments

paulmarshall picture paulmarshall  Â·  3Comments

ianpowell2017 picture ianpowell2017  Â·  3Comments

bityob picture bityob  Â·  3Comments

JamesDLD picture JamesDLD  Â·  3Comments