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

Assert call order? #684

Closed
amoffat opened this issue Oct 19, 2018 · 6 comments
Closed

Assert call order? #684

amoffat opened this issue Oct 19, 2018 · 6 comments

Comments

@amoffat
Copy link

amoffat commented Oct 19, 2018

Hi, great project. Is there any way to assert the order that methods were called? What's the best way to do it? I'm assuming it is iterating over the mock's calls, and doing something, but I am imagining that the "something" means rewriting a lot of the argument checking logic by hand :)

Thanks!

@bkielbasa
Copy link

why do you need such a possibility?

@amoffat
Copy link
Author

amoffat commented Nov 29, 2018

How do you check that a mock's methods were called in a specific order? Sometimes your test is only correct if there is an ordering to events.

@bkielbasa
Copy link

IMO you should check the output of the function but not how it works internally. It may lead to testing implementation which is very hard to maintain.
For example, in the library https://github.com/DATA-DOG/go-sqlmock this methodology was used and because of that, in every case you use the library, you have to add proper assertions in the same order you have in the implementation. For me - it is complicated for more than 2 services with some logic and access to the DB.

@amoffat amoffat closed this as completed Nov 29, 2018
@ran-berenfeld
Copy link

IMO there are cases to enforce order. i.e if you mock a mutex, you better check that Lock was always called before Unlock. We can have a simple implementation where the mock has an "assertExpectationsInOrder" true/false flag that can be set before any expectations are added.

@guenhter
Copy link

guenhter commented Mar 3, 2022

If you take a simple example like io.ReadCloser.
You want to assert that the Close function is called AFTER the read function and that no read happens any more if the close is already called.

@brackendawson
Copy link
Collaborator

This is covered under #741

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

No branches or pull requests

5 participants