Sitelet https://github.com/flutter/flutter/issues/33274
Skip to content

flutter_tools/test/src/context.dart has non-mock "Mock*" classes #33274

Description

@stuartmorgan-g

There are various classes in context.dart that are called Mock* but are not actually mocks. It seems random, and possibly just an oversight. For instance:
class MockXcodeProjectInterpreter implements XcodeProjectInterpreter
but
class MockIOSSimulatorUtils extends Mock implements IOSSimulatorUtils
This is bug number 1.

It looks like they are intended for use in the default testUsingContext, but are public (I would argue that being public is bug number 2).

Taking the MockXcodeProjectInterpreter example, test files that actually want to mock that class have:
class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {}
This shadows the version in context.dart (bug number 3).

When you put all this together, you end up with the very surprising behavior that if you take a working test using a local MockXcodeProjectInterpreter and move it to a new file, but neglect to add a local override in that new file, everything compiles just fine and you get mysterious Mock method was not called within 'when()' errors and waste a lot of time trying to figure out what's going on.

I would argue that at a minimum

  1. Classes named Mock* need to be Mock objects.
  2. context.dart shouldn't be vending objects that are being silently shadowed in test files.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our testsc: contributor-productivityTeam-specific productivity, code health, technical debt.team-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions