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

1

8

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?

Shaftesbury answered 21/6, 2016 at 9:13 Comment(0)
P
1

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.

Pesek answered 30/5, 2021 at 14:14 Comment(1)
Update: I opened a PR in the project to add this functionality: github.com/stretchr/testify/pull/1082Pesek

© 2022 - 2024 — McMap. All rights reserved.