Some Other Assertions in VS Unit

Folks are often unaware of a some classes within the Visual Studio unit testing framework that make writing unit tests a bit easier. Instead of simply adding functionality to the base Assert class, the framework declares 2 other specialized assertion classes: CollectionAssert and StringAssert.

CollectionAssert is handy for comparing 2 collections or for validating members within a single collection. Here is a shot from VS2008 on the CollectionAssert class. This functionality has been there since vs2005, but unless you know it’s there you may have not seen it.

image

String.Assert is a smart little specialty assertion class that helps us work with strings. There functionality in there to let us work with formats and regular expressions.

image

It’s true that you can get this functionality from the standard Assert class, but it takes a little more code to pull it off and these things are there to save us the keystrokes. Enjoy!

One thought on “Some Other Assertions in VS Unit

Comments are closed.

Proudly powered by WordPress | Theme: Code Blog by Crimson Themes.