Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify*Interactions methods throw helpfully that they expect Mock #92

Merged
merged 3 commits into from
Feb 21, 2018

Conversation

srawlins
Copy link
Member

@srawlins srawlins commented Feb 8, 2018

So, the alternative is to Use-The-Damn-Language-Like-You're-S'posed-To-™ and type the incoming argument.

However, when playing around with this internally, I think it actually gets in the way a lot. You see this a lot:

main() {
  HttpClient httpClient;

  setUp(() {
    httpClient = new MockHttpClient();
  });

  test('foo', () {
    // ...
    verifyZeroInteractions(httpClient);
  });
}

class MockHttpClient extends Mock implements HttpClient {}

Which would start throwing static analysis errors, because httpClient is declared as a HttpClient, not a Mock. You'd have to change the type at the declaration to MockHttpClient.

(A) This would be a lot of work to upgrade existing code, for little benefit. (B) I think this produces more overhead for a developer than is helpful: you want to think of your mock objects as really almost basically just the same thing as the type they are mocking. Typing all your mock objects to the type that they implement is intuitive (it's done everywhere).

@matanlurey
Copy link
Contributor

Though, you probably want to write the code like this:

if (mock is Mock) {
  // use
} else { 
 // throw
}

... to take advantage of type promotion.

@srawlins
Copy link
Member Author

srawlins commented Feb 9, 2018

Lol I sort of did it this way in silent protest that this way doesn't already feature type promotion! dart-lang/sdk#25565

I can change it though.

@srawlins srawlins merged commit 4f784f3 into dart-lang:master Feb 21, 2018
@srawlins srawlins deleted the help-verify branch February 21, 2018 01:06
srawlins added a commit that referenced this pull request Apr 16, 2018
* master:
  Remove upper case constants (#113)
  Bump to 3.0.0-alpha+3 (#112)
  Switch back to Chrome for Travis (#104)
  Try using a staged, fancy travis config. (#100)
  Update travis script to actually run dartanalyzer (#102)
  verify*Interactions methods throw helpfully that they expect Mock (#92)
  First draft of upgrade guide for Mockito 3.0 (#96)
  Generic support for `thenReturn` and `thenAnswer` (#101)
  Remove references to `@proxy`. (#99)
  Remove Spy docs (#97)
  Remove mirrors implementation (#91)
mosuem pushed a commit to dart-lang/test that referenced this pull request Oct 17, 2024
…rt-lang/mockito#92)

verify*Interactions methods throw helpfully that they expect Mock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants