ObjectSharp Blogs

You are currently viewing

Dave Lloyd's 2 Cents

A .NET Developer's Perspective


Microsoft Research Part II

On the plane going to PDC Bruce mentioned a new product from MSR that he had downloaded called Pex. Then when the Expo hall opened at PDC we eventually made our way to the MSR section of the hall. There was Pex. We watched an excellent and very enthusiastic demo, at the end we were told there would be a session first thing Thursday morning. That would be the last thing we do before heading for home.

Thursday morning we arrive at the Convention centre for Breakfast, randomly select a table and settle in for breakfast with four other PDCer's. Turns out two of them work for MSR and are giving the talk on Pex this morning. :) It was meant to be, how many signs does one need.

As it turned out Bruce decided to find out how MS uses VSTS internally instead of both of us attending the Pex talk. so we split up.

The Pex talk turned out to be two talks.

Code Contracts

Code contracts will be coming in 4.0 and will allow you to add contracts to your classes and methods to express assumptions about the code. These contracts can be used to:

    1. Improve testing via runtime checking
    2. Static contract verification
    3. Documentation generation

    public virtual int Add(object value)
    {
            Contract.Requires( value != null );
            Contract.Ensures( Count == Contract.OldValue(Count) + 1 );
            Contract.Ensures( Contract.Result<int>() == Contract.OldValue(Count) );
            if (count == items.Length) EnsureCapacity(count + 1); 
            items[count] = value; 
            return count++;
    }

Pex

Pex is an automated white box testing tool, that will interrogate your code and build a table of possible inputs to your code that would execute all code paths. From this table of possible test cases you can generate unit tests. If an unhandled exception is found it will show up in bold, once you create the unit test you can then run the test and debug directly into the code path that causes the exception. All from the Pex UI. Very nice demo.

This is definitely worth a look. There are two versions you can download today. One works with the 2010 CTP and an academic release that works with VS 2008.

Comments

    No Comments

Leave a Comment

(required) 
(optional)
(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS