-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement test worker/test framework #281
Comments
Work here is in progress, but likely to span across multiple sprints. We'll decompose this issue and assign more granular tasks. |
@fabiocav, I'm assuming once some of that work can be shared, it will be. Looking forward to trying out what's being built. |
Is there any update on when this would be available? |
Any updates? :) |
do we have any framework to unit test out-of-process azure functions? |
@fabiocav Any updates or availability ETA on this feature especially for .NET 6.0? |
@brettsam is actively investigating this and has made some progress, but there have been higher priority items taking precedence. We'll continue to use this issue to provide updates as we go |
In the meantime does this help?
|
Those who are searching for options - here is one more. I have created Test Doubles for the required classes to get Unit Testing working for a Isolated Process model function app. Here is the repo - https://github.com/lohithgn/az-fx-isolated-unittest. Hope this helps. |
For those of you using Moq, framework, only difference of what @andersson09 suggested is the following changes. Otherwise
|
What’s the latest on this issue? We’d really like to expand our api contract testing to isolated azure functions in dotnet. We can do this with TestSever for our dotnet core mvc apps. What’s the ETA? |
@fabiocav would appreciate any update on this front. please let us know where this heading ? |
@fabiocav Is this being currently worked on? |
Hi @fabiocav, there haven't been any updates on this feature for quite some time. Is this something we can really expect to happen? If so, do we have any rough idea of the priority or an ETA? If we can expect this sometime this year or even in 2023 Q1, I'd put less effort into making our own framework while writing tests for a new isolated functions service. Thanks! |
looking forward to an update on this also! |
Any updates on this? That the unit test story for isolated functions is half baked isn't called out anywhere in the documentation. 2 years since this issue was opened. Since in-process functions are not being iterated on, anyone who has a cache of large unit tests will run into this issue while migrating. @fabiocav appreciate your work on this but is there any update/ETA on this? |
I think I m close to be able to do a PR that would allow integration testing using testserver handler for grpc. I have a working example on my fork. But some part are still hard coded. |
As above, very interested in this. |
Whichever option you choose, I like code re-use. There are a lot of "gotchas" that makes the MVC TestServer not usable in certain circumstances. For example, TestClient doesn't have the same stack of HttpHandlers as a non-test HttpClient. This means you can't test telemetry (AppInsights, OpenTelemetry), distributed transactions, and other things. I'd prefer if they'd used a regular HttpHandler and modified it as needed. I think another one is you can't inject HttpHandlers into DI to be used on HttpClient creation (can't remember if that's accurate). At any rate: code reuse = ++++ |
You are wrong on this as you can create the test handler only . And so add all the delegating handler you want. The only real problem I ever met was that the content stream was not the same for the test handler than Real http call. And didn t check if it was change in later version |
Hmm.. I guess I'll have to revisit. When I last looked, the HttpClient had a SocketHandler that got in the way, but maybe that can be bypassed and replaced with the DelegateHandler wrapped around a TestServerHandler? And going from the other direction, DiagnosticHandler wasn't public and couldn't be added to the TestHttpClient. |
Iam quite stumped there's no easy way to do integration tests with azure functions like we can do with asp .net. For me this really feels azure functions is not mature yet. What surprises me even more that this issue is quite old already. Does this not have priority? |
@Barsonax, if you read carefully, in one of the comments of this or other linked issues, @fabiocav mentioned that unit test support is not such important and AZ func team has tasks with higher priority to implement. |
Ah missed that, if that's really the case then that priority is wrong imho. But then again that's just my naive opinion.
This is what I was doing but yeah it annoys me it's so hard to test the whole app. There will always be gaps if you only do simple unit tests.
Totally agree, we are actually moving some functionality away from functions to a simple asp .net api because it's less complex. Some of the triggers are nice though but iam definitely keeping the functionality there to a minimum until this is fixed. |
Yeah, there's a lot to be desired where writing automated tests against Azure isolated functions is concerned. There's also the hard dependency on If I had to do it all over again, I'd probably do what @Barsonax did & use ASP.NET Web API (which is robustly supported) instead of Azure functions for some of the work I'm doing. |
That one is going to be resolved in the coming days as it's already working and just missing documentation.
If you're testing a trigger and need to pass in a raw message ( But in general, I agree. Having a foundational testing framework would be beneficial. |
@SeanFeldman Amazing! And thank you for providing these updates, regardless of whether or not the underlying issues are being worked on. Communication -- of awareness, intent, and/or progress -- goes a long way towards allaying frustration. |
This item should also cover the related work captured in #304 |
For using Moq, I share with you how to implement this solution using Moq to test Azure Function Isolated .Net 8
|
Any updates? |
I came up with this until there is something like we have for ASP.NET Core applications. |
I came across this project https://github.com/wigmorewelsh/FunctionTestHost, just given it a go with a .net 6 isolated function and it works nicely. |
Any updates on this? |
I might as well ask as it's been a couple of months...... any updates? |
It seems that the newish .NET Aspire framework is a great fit for testing isolated Azure Functions. They're using the Visual Studio "IDE Execution" API to attach a debugger to user code that was started indirectly as sub-processes, spawned by the DCP "orchestration process". https://github.com/dotnet/aspire/blob/main/docs/specs/IDE-execution.md This sounds identical to Visual Studio starting an Azure Function Host which then spawns sub processes (user Function code) containing the user code. |
This is the approach I've implemented in my company , but still lacks the ability to control the DI container (substitute services with mocks and set them up), but this is also solvable... |
So we saw the upcoming end of LTS for .NET 6 in November 2024 and thought, "Crikey! We'd best get a move on and migrate to .NET 8. Might as well jump on to Isolated Process while we're at it.". We initially tried out the ASP.NET Core integration route, maintaining all the familiar IActionResult and HttpRequest types and interfaces, but found that performance tanked instantly by a very noticeable amount (<30ms avg response times for simple HttpTrigger functions under .NET 6 In Process, jumping to >120ms avg response time under .NET 8 Isolated Process. We had expected some performance hit, but that felt like a lot). We then started trying to migrate to the in-built model using HttpResponseData and HttpRequestData and while performance improved, unit and integration testing were damn near impossible. A number of years-long threads of disappointment like this one and no visible process towards a solution is pretty frustrating. |
I strongly think that http api's in Azure functions are always going to be second citizen to just asp .net. Might as well use asp .net then. |
I, like the rest of the commenters here am pretty stunned that there is no MS solution to this yet. I don't think we need to rehash why a robust set of unit tests is fundamental to all good codebases, so this feature really shouldn't have been released without a clear unit testing approach.
Yes, I know. The only other bit you'd be interested in here is the
|
How did you define MockBindingContext ? |
It's pretty straightforward:
|
Implement a test worker and test helpers for public consumption.
This should also be adopted by the worker tests in the project.
The text was updated successfully, but these errors were encountered: