You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
Add option to NewController() (see #238 ) to enable reversing the evaluation order.
Proposal
gmock applies expectations in reverse order. This allows the following pattern:
// sut.gotypeAinterface {
Foo(iint) int
}
typeSomethingstruct{
aA
}
funcNewSomething(aA) *Something {
returnSomething{}
}
func (s*Something) Do(iint) {
s.a.Foo(i)
}
// sut_test.gofuncbeforeEach(t*testing.T) A {
ctrl:=gomock.NewController(t)
mockA:=NewMockA()
// Stub - Always returns 99mockA.
EXPECT().
Foo(gomock.Any()).
Return(99).
AnyTimes()
}
funcTestFoo_OnlyDefault(t*testing.T){
mockA:=beforeEach(t)
s:=NewSUT(mockA)
s.Do(5) // Mock doesn't make any assertion on value
}
funcTestFoo_WithAssertion(t*testing.T){
mockA:=beforeEach(t)
mockA.
EXPECT().
Foo(101).
Return(99)
s:=NewSUT(mockA)
s.Do(5) // Latest assertion will fail
}
This pattern will currently fail as the first assertion is evaluated first, as it is an AnyTimes(), it will always be successful and therefore the last assertion (the one we really care about for TestFoo_WithAssertion) won't be applied.
The text was updated successfully, but these errors were encountered:
Add option to
NewController()
(see #238 ) to enable reversing the evaluation order.Proposal
gmock applies expectations in reverse order. This allows the following pattern:
This pattern will currently fail as the first assertion is evaluated first, as it is an
AnyTimes()
, it will always be successful and therefore the last assertion (the one we really care about forTestFoo_WithAssertion
) won't be applied.The text was updated successfully, but these errors were encountered: