timdeschryver / HowToTestYourCsharpWebApi

54 stars 15 forks source link

unit testing for external API #2

Open kiquenet opened 2 years ago

kiquenet commented 2 years ago

How-to do unit testing for external API (like Fake API ) api.chucknorris.io ?

simple-example-of-calling-rest-api-with-httpclient-in-net5.0

timdeschryver commented 2 years ago

Hi, could you elaborate what/why you want to test an external api?

kiquenet commented 2 years ago

2 scenarios:

1) Test any exteranl REST API Client (ApiClient), for example, or using any REST API of another departaments (Sales, Purchasing, Accounts, Finance , Human Resources, ...), we haven't source code but we need test "API client".

2) Test our internal REST API (webapplicationfactory)

useful references:

Integration-tests-with-webapplicationfactory https://andrewlock.net/exploring-dotnet-6-part-6-supporting-integration-tests-with-webapplicationfactory-in-dotnet-6/

HttpClient and testing https://adamstorr.azurewebsites.net/blog/test-your-dotnet-httpclient-based-strongly-typed-clients-like-a-boss

IHttpClientFactory vs HttpClient https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests

YOU'RE USING HTTPCLIENT WRONG AND IT IS DESTABILIZING YOUR SOFTWARE