While traditional syntax for asserts is fairly easy to understand (once you get used to reading it), it doesn’t read as close to English as I’d like. So I have taken to using the Assert.That syntax for a lot of my assertions. This makes an assert like this:

   1: Assert.AreEqual(5, SUT.Items.count);

Read like this:

   1: Assert.That(SUT.Items.Count, Is.EqualTo(5));

To me, the second assert reads a lot more like plain English.

 

~Lee

posted on Monday, October 13, 2008 11:01 AM | Filed Under [ TDD ]

Comments

Gravatar
# re: NUnit Assert.That Syntax Makes Assertions Easier to Read
Posted by karami
on 10/29/2008 6:31 AM
would you please help me about UnitTest(C#) and details of it and assert 's methods
Gravatar
# re: NUnit Assert.That Syntax Makes Assertions Easier to Read
Posted by Lee Brandt
on 10/31/2008 5:17 AM
http://www.xprogramming.com/xpmag/acsUsingNUnit.htm This is a good referencefor getting started as well as Pragmatic Unit Testing In C# with NUnit book.

Hope this helps,
~Lee
Post Comment
Title *
Name *
Email
Url
Comment *