Partager via


Trying out Code Contracts from Microsoft Research

There are two sections that get added to VS 2008 after you install the add-in from MSR to test Code Contracts.  The first one is simply called 'Contracts'.

Contracts configuration in VS 2008

The second tab is named 'Code Contracts'. 

Code Contracts configuration in VS 2008

The MSR team did a presentation at PDC08 about Code Contracts and the Pex automated-testing tool.

In the area of contract-based coding at Microsoft, there is also Spec#.  Sample shown below.

 using System;
using Microsoft.Contracts;

public class Program
{
  static void Main(string![]! args) 
  {
    Console.WriteLine("Spec# says hello!");
  }
  
  public int Add(int i, int j)
  
    requires i > 5;
    requires j < 3; 
    {
        int r = i + j;
        return r;
    }
    
}

Have you had time to look at contract-based coding?  What do you think about it?

Comments