views:

21

answers:

1

I'm build a library inspired by RSpec on top of NUnit 2.5+ in order to improve my tests readability. The source code is available at http://github.com/educobuci/SpecUnit.

This library allows me to write tests like this:

[Test]
public void It_should_returns_0_for_all_gutter_game()
{
    var game = new Bowling();
    for (int i = 0; i < 10; i++)
        game.Hit(0);
    game.Score.Should(Be.Equal(0));
}

The "Should" method is an extension method for all Object that receives basically an Action with some NUnit assertions like that:

public static class Be
{
    public static Action<T> Equal(T to)
    {
        return (target) => NUnit.Framework.Assert.AreEqual(target, to);
    }
} 

The library is working pretty good but I have no tests for the library itself... basically because I don't know how to test it!

So, how can I test it? I mean, how to ensure that "object.Should(Be.Equal(object))" really checks the equality?

+1  A: 
[Test]
public void Be_Equal_action_throws_AssertionException_for_inequal_integers()
{
   var action = Be.Equal(0);
   bool raised = false;
   try
   {
       action(1);
   }
   catch (AssertionException)
   {
       raised = true;
   }
   Assert.IsTrue(raised, "No AssertionException was thrown");
}
Wim Coenen
Actually I'm going to use Assert.Throws/DoesNotThrow, but that is the idea. Thank you!
Eduardo Cobuci