Search code examples
nunitmoqverification

Unit tests with mock verifies


I have a unit test that

  1. creates a mock
  2. calls my method to be tested (also injecting my mock)
  3. asserts method results
  4. verifies mock calls

When mock calls don't verify as expected I get an exception, thus failing a test.
How should I correctly call this verifies? Should I just be calling

// verify property get accessor call
m.VerifyGet<bool>(p => p.IsRead, Times.AtLeastOnce());

or should I call it with Assert

// verify property get accessor call
Assert.DoesNotThrow(() => m.VerifyGet<bool>(p => p.IsRead, Times.AtLeastOnce()));

When verify fails I get an exception anyway.
What's the proper way of mock verifying?


Solution

  • VerifyGet is enough, assert seems to add no value so why add more verbiage?