22 Feb

Some Other Assertions in VS Unit

Category:UncategorizedTag: , , :

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.


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.


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.