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

MissingStubError when mocking DateTime: 'hashCode' / '==' / 'toString' #420

Closed
boldt opened this issue Jun 1, 2021 · 5 comments
Closed
Assignees
Labels
P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@boldt
Copy link

boldt commented Jun 1, 2021

We're trying to migrate our mockito-tests to null-safety. We followed the null-safety guide.
Now we see the following issues, when we are "working" with the stubs (like expect or indexOf in an array):

1) MissingStubError: 'hashCode'

MissingStubError: 'hashCode'
No stub was found which matches the arguments of this method call:
hashCode

2) MissingStubError: '=='

MissingStubError: '=='
No stub was found which matches the arguments of this method call:
==(MockDeviceModel)

3) MissingStubError: 'toString'

MissingStubError: 'toString'
No stub was found which matches the arguments of this method call:
toString()

Our use case

Our codes works on lists. Thereore, our tests use a list of mocks and thus, tried to compare them, which fails finally.

Our setup

  • dart: 2.13.0
  • flutter: 2.2.0
  • mockito: 5.0.8

Issue

Mocks do not handle hashCode / == / 'toString'

@boldt boldt changed the title MissingStubError: 'hashCode' / '==' MissingStubError: 'hashCode' / '==' / 'toString' Jun 1, 2021
@boldt
Copy link
Author

boldt commented Jun 1, 2021

MWE for MissingStubError: 'toString'

@GenerateMocks([
  DateTime,
])
void main() {
  test("MissingStubError: 'toString'", () {
    var mockDateTime = MockDateTime();
    expect(mockDateTime, mockDateTime);
  });
}

Issue:

MissingStubError: 'toString'
No stub was found which matches the arguments of this method call:
toString()

Expected

expect should return true, when a mock is used.

@boldt
Copy link
Author

boldt commented Jun 1, 2021

MissingStubError: 'hashCode'

  test("MissingStubError: 'hashCode'", () {
    var mockDateTime0 = MockDateTime();
    var mockDateTime1 = MockDateTime();
    var arr0 = [mockDateTime0, mockDateTime1];
    var arr1 = [mockDateTime0, mockDateTime1];
    expect(arr0, arr1);
  });

Issue

MissingStubError: 'hashCode'
No stub was found which matches the arguments of this method call:
hashCode

@srawlins srawlins changed the title MissingStubError: 'hashCode' / '==' / 'toString' MissingStubError when mocking DateTime: 'hashCode' / '==' / 'toString' Jun 1, 2021
@srawlins
Copy link
Member

srawlins commented Jun 1, 2021

I think this might happen for any class which overrides toString, hashCode, or operator==, but it would be surprising that we haven't seen this error yet.

In any case, we do have bugs for classes which override these methods and add optional parameters, so we should fix the two in one go.

@srawlins srawlins self-assigned this Jun 1, 2021
@srawlins srawlins added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P2 A bug or feature request we're likely to work on labels Jun 1, 2021
@srawlins
Copy link
Member

srawlins commented Jun 7, 2021

This should be fixed in mockito 5.0.10.

@srawlins srawlins closed this as completed Jun 7, 2021
@boldt
Copy link
Author

boldt commented Jun 8, 2021

I can confirm, that my borken tests succeed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants