NUnit is an excellent utility in supporting application
development. Based on JUnit, NUnit tests .NET applications by making assertions
about the code, allowing you to compare properties within your objects for
certain values. For the unit test to succeed, all of the assertions must
evaluate to true, or the test fails. There are complexities with unit tests; not
every object has public properties, which makes it harder to test. It is
possible to do through the Reflection API objects which inspect the metadata
and get the value of the property.
Some complexities with application code exist, such as
classes marked with the friend/internal class modifier. If the unit test exists
outside of that project, it is not possible to test these types, except through
the classes that use them, with one exception: adding the InternalsVisibleTo assembly
attribute for the project that has the internal types. InternalsVisibleTo
references an assembly that permits its internal types to be visible to that
class by designating the assembly information for that project. Though MSDN
documentation states that the projects it references should be strongly-typed,
I have read blog entries that use local assemblies and have done it in one of
my projects as well.
I wrote an article about using a product called TypeMock, which is a
powerful mocking library capable of performing complex unit tests. All of
these are features that are very helpful when creating unit tests. And lastly,
the newest version of NUnit contains additional assert objects for comparing
collections, files, and strings, all of which are very useful and handy to
have.
That got me curious, as I like the ability to have additional
assertions than the standard set. Additional assertion objects have the
ability to add a powerful set of assertion features that can make some of the
unit testing easier. For instance, it would be nice to have assertions that
reflected against an object, or assertions that poll a data table or row. This
article is going to go further into that, examining some of the essential
objects, such as the various types of constraint objects that perform the
matching of the objects.