I finally got around to upgrading to the most recent version of NUnit recently (Yea I know, bout time) and found out that there is a new way of doing assertions. The new model is referred to as the 'constraint' model and follows a more fluent style interface. Below are some examples in syntax between the 2 models.
Classic Model examples
Assert.IsNull( objectHere );
Assert.AreEqual( value1, value2 ):
Assert.IsTrue( boolValue );
Constraint Model examples
Assert.That( objectHere, Is.Not.Null );
Assert.That( value1, Is.EqualTo( value2 ) );
Assert.That( value1, Is.True );
My initial reaction to the new style of assertions was that I did not like it. I felt that Assert.IsNull() was cleaner than Assert.That (x, Is.Null ). However, after I read up on the documentation for the new model ( here ), I started to like it more and more. I have always been a fan of fluent interface style syntax because to me it reads more like English (insert your language of preference here). Also, if you read the documentation, with the latest release (post 2.4 really) the classic model now just hides the constraint model, so why not just use the constraint model to begin with.
Anyway, I was kind of excited to see the model and the possibilities it brings, but also a little 'put off' because now I have to learn something new....:(
Till next time,
01-09-2008 6:44 AM