Skip to content

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

@jamesderlin

Description

@jamesderlin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    a.cookbookRelates to a cookbook recipe or guided.enhancementImproves docs with specific aske2-daysEffort: < 5 daysfrom.page-issueReported in a reader-filed concernp2-mediumNecessary but not urgent concern. Resolve when possible.test.generalRelates to unit, integration, perf testingtest.unitRelates to unit testing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions