views:

98

answers:

2

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?

+2  A: 

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

djna
+1  A: 

The DoesNotThrow-method should be used to test whether your own methods adhere to your specifications.

In short, adding the DoesNotThrow looks like you're testing the behaviour of VerifyGet instead of the behaviour of your SUT.

Of course, you can wrap it around the VerifyGet, but I think that only makes things confusing since VerifyGet would fail the test anyway.

Lennaert