Leveraging overloaded Assert() methods to enhance test methods.
Continuing from my TDD: Mocking with Dummy objects article, I wanted to illustrate some examples of other Assert() methods available for use to enhance testing results.
As illustrated in my last example, you may just utilize the traditional Assert.AreEqual()
method, passing it the expected and actual results to determine pass/failure results
or you may use a more granular approach – by using a more explicit test, choosing
the method by which the values would be compared.
In the first example, I’m choosing to manually compare both values using the “equals”
If both values are found to be equal, Assert.Pass() notifies the framework that
Conversely, if the values were not found to be equal, the test fails.
In my next use of Assert(), I’m choosing to perform a similar test – comparing string values, except this time I’m wrapping the results in IsTrue() function which notifies the testing framework of the results.
Finally, sometimes it may be necessary to determine if a value is/is not null.
In this example I’m choosing the optimistic IsNotNull() approach.
As you can see, all my tests have passed.