# Thursday, October 01, 2009
« Visual Studio webtests hurt my eyes | Main | I’m enjoying learning Erlang »

I found another reason to love open source NUnit over MSTest, NUnitEx. NUnitEx provides a fluent DSL to write NUnit assertions where Visual Studio intellisense is your guiding friend. I’m sure you’re thinking, “Yeah whatever, show me some code.”

[Test]
public void AdjacencyGraph_is_directed_by_default()
{
    var graph = new AdjacencyGraph<Task, TaskDependency>(DoNotAllowParallelEdges);
    graph.IsDirected.Should().Be.True();
}

Nice eh? graph.IsDirected is the property I want to test.  Everything after that is the NUnitEx extension methods. I know I find it much more readable than this:

[Test]
public void AdjacencyGraph_is_directed_by_default()
{
    var graph = new AdjacencyGraph<Task, TaskDependency>(DoNotAllowParallelEdges);
    Assert.IsTrue(graph.IsDirected);
}

I would also like to add that this syntax is likely to be included in NUnit 3, which would be excellent!

Monday, October 19, 2009 4:58:05 AM (GMT Standard Time, UTC+00:00)
I had the same feeling when the Constraint-Based Assert Model (http://nunit.com/index.php?p=constraintModel&r=2.4) was first introduced a couple of years ago in NUnit 2.4 with the use of 'Assert.That' syntax:

Assert.That(graph.IsDirected, Is.EqualTo(true));

I found it more natural to read and write than the older syntax and immediately started writing all new tests using it. However, not sure if that ever caught on in popularity.

It was definitely an early attempt at fluent DSL by NUnit but, unlike the newer syntax in your post, was still weighted down by the old testing syntax of having explicit Assert keywords.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview