Showing posts with label nunit. Show all posts
Showing posts with label nunit. Show all posts

Tuesday, 21 April 2009

NUnit's EqualTo tolerance modifier

Comparing generated DateTime values can always be a bit tricky, but today I discovered NUnit's Within modifier that makes life so much easier:

[Test]
public void CreatedOnDefaultsToNow()
{
SomeClass someObject = new SomeClass();
Assert.That(someObject.CreatedOn,
Is.EqualTo(DateTime.Now).Within(new TimeSpan(1000)));
}