Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assert that mocked method calls happen in-order with testify?

The documentation for AssertExpectations says "AssertExpectations asserts that everything specified with On and Return was in fact called as expected. Calls may have occurred in any order." What if I want to assert that some calls happen in-order?

gomock has *Call.After(*Call) for this, but I can't see anything similar in testify. Is there a way, or should I just use gomock?

like image 783
barrucadu Avatar asked Jun 21 '16 09:06

barrucadu


1 Answers

Testify does not support this feature currently, but it's tracked in this issue https://github.com/stretchr/testify/issues/741.

Testify's mock.Mock object provides access to the ordered calls through the Calls property (https://pkg.go.dev/github.com/stretchr/testify/mock#Mock), which you could use to build this functionality yourself.

like image 123
Cameron Little Avatar answered Nov 03 '22 19:11

Cameron Little