flutter / website

Flutter documentation web site
https://docs.flutter.dev
Other
2.82k stars 3.22k forks source link

Change mocked dependency from http.Client on 'Mock dependencies using Mockito' page #6924

Open jamesderlin opened 2 years ago

jamesderlin commented 2 years ago

Page URL

https://docs.flutter.dev/cookbook/testing/unit/mocking/

Page source

https://github.com/flutter/website/tree/main/src/cookbook/testing/unit/mocking.md

Describe the problem

I've seen numerous questions on StackOverflow from people trying to manually create a Mock for package:http's http.Client.

The Flutter cookbook page demonstrating mocking does exactly that, and I think it's steering people the wrong way. Mocking http.Client can be tricky since the stub might be called with a headers argument that they don't expect.

Furthermore, it's unnecessary. package:http provides its own MockClient class to make testing easier.

Expected fix

Create a different example that mocks something else.

Additional context

danagbemava-nc commented 2 years ago

@jamesderlin, thanks for the feedback