website icon indicating copy to clipboard operation
website copied to clipboard

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

Open jamesderlin opened this issue 3 years ago • 1 comments

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

  • https://stackoverflow.com/q/71490908/
  • https://stackoverflow.com/q/71381940/
  • https://stackoverflow.com/q/71472691/ (maybe)
  • https://stackoverflow.com/q/71452160/ (maybe)

jamesderlin avatar Mar 16 '22 03:03 jamesderlin