web 2.0

Snow!

Thanks to the snow, my blogging and side activities have been sidelined for awhile.  I have been spending a considerable amount of time looking into Pex and Code Contracts.  Pex is a surface testing solution that runs your code through the ringer and gives you a set of methods that you can unit test against.  It is even slick enough to create the unit test for you if you want. 

Let me give you a VERY simple example:

public int PexMethod(int left, int right)
{
    return (left / right);
}

This is a very simple method with a lot of issues.  The simplest being that it doesn’t do any input checking.  Pex will do a surface scan and return a vast set of inputs that you can put into this method to “break it”.  For instance, Pex will tell you that the method will throw an error if you pass in 0 for the right integer.  It will also be smart enough to check for ArithmeticOverflow exceptions.  If this was a custom object, Pex would also check the method’s behavior if null values are passed in.  I would love to go into more detail, but I think the Pex team does a much better job than I ever can:

pexweb

Tags: