NUnit constraints offer a different style to crafting your unit tests, rather than write. Assert.IsEqual( expected,actual ) you could write Assert.That( expected , Is.EqualTo( actual )) Or in VB as Is is a reserved keyword - Assert.That( expected , [Is].EqualTo( actual )) 'Is' is one of the syntax helpers within NUnit.Framework.SyntaxHelpers to add a little syntax sugar, the above could be written as Assert,That(expected, new EqualConstraint( actual )) Where EqualConstraint lives in NUnit.Framework.Constraints but the syntax sugar is so much nicer. The That assert takes a IConstraint interface and if you want to craft your own constraints you can do so by using NUnit's own Constraint class. For our own purposes let's create a custom constraint that tests the cast of null (nothing) to a datetime value. Imports NUnit.Framework Imports NUnit.Framework.Constraints Public Class DateFormatConstraint Inherits Constraint Private testDate As Date Public Sub New() Me.testDate = CType(Nothing, Date)
Read More...