Assert and Verification
While the .NET gives you convenient methods for asserting different conditions into your unit tests, it still doesn’t cover some behaviors that can be set up when using JustMock. That is why, JustMock exposes several asserting methods to help you verify the behavior is what you expect.
When setting that a specific method must be called, or a set of methods should be called in a specific order, the actual execution must be then verified with the Mock.Assert
method. To illustrate the exact usage, we will use the following setup:
Sample setup
Example 1 shows how you can set up a test verifying that the Complete
method is first invoked, followed by HasInventory
and Remove
is last in the chain:
Example 1: Verify the order of invocation for several methods
More information on how you can set up a specific occurrence of members is available in the Asserting Occurrence topic.
In addition to the behavior of the class members, you can also assert a property setter.
Example 2: Verify property setter
Next Steps
As a next step we recommend you to check the Mock Static or Extension Members article that shows how you can test any static implementation.