What is the purpose of Verifiable()
?
If I verify a Mock
and leave this out it still verifies the SetUp
.
Edit: I was using VerifyAll()
thus the reason for everything being verified. After changing to Verify()
only my .Verifiable()
SetUp
s were being checked.
Best Answer
ADDENDUM: As the other answer states, the purpose of
.Verifiable
is to enlist aSetup
into a set of "deferredVerify(...)
calls" which can then be triggered viamock.Verify()
.The OP's clarification makes it clear that this was the goal and the only problem was figuring out why it wasn't working, but as @Liam prodded, the answer should really touch on this too:- The key use cases as far as I can see are:
mock.Setup()
andmock.Verify
Verify
call itself (e.g., you could set it up in another helper method)... and back to my answer, which tersely effectively says "be careful as the above pros are commonly considered to be outweighed by the effect that achieving those goals has on the legibility and maintainability of tests which lean too much on such constructs"
ORIGINAL: Note that where possible, one should instead follow the AAA layout and hence one should be doing explicit
mock.Verify( expression )
calls after the work has been done, rather than amock.Setup( ... ).Verifiable()
paired with amock.Verify()
ormock.VerifyAll()
wherever possible (credit: @kzu).