First steps with Machine.Specifications (BDD framework)

Old machine. Where is the specification?
Figure: How do you specify this machine?

As you may have read in my previous blog post: On the road to BDD… Or… to see the light, I am dabbling more and more into the ATDD / BDD world.

These are my impressions from Machine.Specifications.
BTW: Gread video from JP Boodhoo about Getting up and running with MSpec

1st impression:

  • It takes a little while to get used to the funky () => syntax,
    but now I love the readability of my tests...


Sample tests

    public class When_Adding_a_String_With_2_Numbers
        Establish c = () =>
                calculator = new Calculator();

        Because b = () =>
                result = calculator.Add("1,2");

        It Should_return_the_sum_of_the_string = () =>

        static int result;
        static Calculator calculator;

    public class When_Adding_an_Empty_String 
        Establish c = () =>
                calculator = new Calculator();
        Because b = () =>
                            result = calculator.Add("");

        It Should_return_0 = () =>

        static int result;
        static Calculator calculator;


I love this test output:

When Adding AString With 2  Numbers
» Should return the sum of the string

When Adding An Empty String
» Should return the sum of the string

Contexts: 2, Specifications: 2, Time: 0.21 seconds

Figure: Test output of the mSpec runner - Underscores get replaced with spaces in the test output.
BTW: I heard the new runner for xunit in VS2012 does that as well.


My 2cents:

  • I need to figure how to structure my tests better to get the nice distinction between Scenarios and Features
  • I would say that the MSpec Framework is more designated for developers that want to discuss and show the test output to the business people.
    Working on the tests itself (code) together with the business is not an good option with MSpec
  • It feels weird at the beginning when there is a class that is your test. Instead of a method that is your test
  • Duplication needs to be taken care of by refactoring out into base classes or Factory methods


What is your impression of mSpec?

1 comment:

Anonymous said...

Keep visiting this blog site.Thanks for sharing it.

.net Programmer

Post a Comment

Latest Posts

Popular Posts