Aspnetcore.docs: How to test with DI'd HttpClients?

Created on 24 May 2019  Â·  6Comments  Â·  Source: dotnet/AspNetCore.Docs

Is there a chance we could get a section on how to write tests against this? Typically I run the "real" Startup class in order to get the real DI container and then swap in external services like HTTP and AWS with mocks. HttpClient is not mockable so I'm currently riding the struggle bus on how to get a mock HttpMessageHandler into the mix.


Document Details

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

PU Source - Docs.ms doc-enhancement

Most helpful comment

I have a partially completed, long overdue post on testing with HttpClient and HttpClientFactory. I'll try to pick that up again after my upcoming vacation and share the link. Happy to help distil some of that into a doc afterwards if appropriate.

All 6 comments

If we do something specific, it would probably be better in either the unit testing or integration testing topics.

I'll mark this for the Integration Testing project. The product unit can decide if they want us to pursue it.

I have a partially completed, long overdue post on testing with HttpClient and HttpClientFactory. I'll try to pick that up again after my upcoming vacation and share the link. Happy to help distil some of that into a doc afterwards if appropriate.

cc: @tdykstra @Rick-Anderson ... :point_up:

some of that into a doc afterwards if appropriate.

If it boils down to just mocking a few objects correctly, I wonder if it can be covered with an added section (possibly with a sample app example).

btw @tdykstra Would the MVC controllers testing doc be better off in the Test, debug, and troubleshoot node with the rest of the testing docs? If so, I could move that TOC entry when I work on Test, debug, and troubleshoot enhancements (aspnet/AspNetCore.Docs #10150), which is coming up quick for work.

Would the MVC controllers testing doc be better off in the Test, debug, and troubleshoot node with the rest of the testing docs?

Yes that makes sense.

Moved to the tracking issue for this topic: Integration tests MASTER issue #16341

Was this page helpful?
0 / 5 - 0 ratings