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

Problems with mockito #24

Closed
creativecreatorormaybenot opened this issue Mar 6, 2021 · 7 comments · Fixed by #47
Closed

Problems with mockito #24

creativecreatorormaybenot opened this issue Mar 6, 2021 · 7 comments · Fixed by #47
Assignees
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@creativecreatorormaybenot

Hi :)

As mocktail looks like a promising alternative to mockito that still provides a nice API, I was wondering how mocktail solves the problems that made mockito turn ugly :)

I checked the repo and could not find this documented anywhere. So essentially: how does mocktail solve the problems described at https://github.com/dart-lang/mockito/blob/9f107e6805f1778cc611f369a8b3338ebf120639/NULL_SAFETY_README.md#problems-with-typical-mocking-and-stubbing?

@felangel
Copy link
Owner

felangel commented Mar 6, 2021

Hey @creativecreatorormaybenot 👋
Thanks for opening an issue!

Mocktail solves these issues by wrapping the stubs and verifications in a closure which allows the library to execute the stub/verification and handle the TypeError internally. Hope that helps! 👍

@felangel felangel self-assigned this Mar 6, 2021
@felangel felangel added the question Further information is requested label Mar 6, 2021
@creativecreatorormaybenot
Copy link
Author

Thanks a lot for the response @felangel ❤️

Further questions: how does this compare to mockito? Are there drawbacks to the mocktail approach?

From your perspective: would you say this is a better approach or just different (emphasis on "your perspective" 🙃)?

@felangel
Copy link
Owner

felangel commented Mar 6, 2021

No problem! The main drawback to this approach is that if you want to use an arg matcher (any, captureAny) for a custom type you need to register a fallback value

setUpAll(() {
  Mocktail.registerFallbackValue<MyType>(MyType());
});

when(() => foo.bar(any<MyType>()).thenReturn(...);

I personally think that this approach is still easier, more convenient, and closer to the previous mockito api than the latest mockito release. I’ve opened a proposal to merge mocktail into mockito which you can check out at dart-lang/mockito#347 🙂

@creativecreatorormaybenot
Copy link
Author

creativecreatorormaybenot commented Mar 6, 2021

I see, thanks a lot for that @felangel 🙏

My strawman take on this is that I agree with you 😜 Furthermore, I do not think that arg matchers are worth destroying the syntax anyway 😄 I have not yet experienced cases where I would need them in unit testing.

@creativecreatorormaybenot
Copy link
Author

Do you want to leave this open as a reference for others @felangel?

Otherwise, I would be fine with closing this. Although an in-depth explanation going into the technical details would likely be helpful in general. I suppose one could also transform this into a documentation request :P

@felangel
Copy link
Owner

felangel commented Mar 6, 2021

Do you want to leave this open as a reference for others @felangel?

Otherwise, I would be fine with closing this. Although an in-depth explanation going into the technical details would likely be helpful in general. I suppose one could also transform this into a documentation request :P

Yeah let’s keep it open until we document the approach better 👍

@felangel felangel added the documentation Improvements or additions to documentation label Mar 6, 2021
@kuhnroyal
Copy link

Thanks for sharing this information and your views! Maybe pin this issue :)

@felangel felangel pinned this issue Mar 7, 2021
@felangel felangel unpinned this issue May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants