TDD: Assets

Please see my other Test Driven Development articles.

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
is passed.
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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s