Showing posts with label Code Contracts. Show all posts
Showing posts with label Code Contracts. Show all posts

Thursday, October 11, 2012

[Tutorial] Test Driven Development with Visual Studio 2012
Part1: Introduction to TDD

In one of my blog posts series, I showed you how to increase the quality of your code and how to make it much easier to maintain by applying the S.O.L.I.D. principles. I then focused on the Liskov Segregation Principle (LSP) by using Code Contracts in .NET 4.0. This blog series is going to talk about Test Driven Development (TDD) in an Agile environment using the latest Visual Studio 2012 features and how that is going to help you to be more efficient and productive.

The goal of this series will be to show you some of the new features within Visual Studio 2012, that are going to help you when trying to apply the TDD approach. The first parts of the series are more theoretical, while as the last part will be fully practical, since we are going to implement some example code using TDD.

Contrary to traditional software development methodologies and processes, where writing unit test is often done as last step after code implementation, TDD consists of writing unit test upfront as first step in the software development cycle. No development can be started without having implemented the corresponding unit tests. You understand that TDD has large impacts on the organization of your teams.

The following are the different steps when applying Test Driven Development :

image

  1. Write a unit test for a new functionality, then validate that the test fails, since its implementation has not been realized
  2. Implement the minimum code necessary to pass the test, then validate that the test passes successfully, meaning that the expected behavior is now provided by the implementation
  3. Refactor and optimize your code, the unit tests ensure the coherence of the functionalities

Using TDD helps in obtaining a code source that is very reliable, predictable, robust - and after refactoring - highly optimized. Unit tests ensure a correct behavior, independently from where it is going to be used, resulting in a code source that will work as expected under any circumstances.

For being able to create good unit tests, you have at first to think about the conception and software design of your application. You must not hurry into doing your implementations, before being clear about your objectives (which should be true for any development, but sadly often it is not).

Conceptual errors can be detected and resolved much quicker and in a much more efficient way. As explained the implementation is started only after the conceptual phase has been validated and tested via thorough unit tests. In this case, your unit tests become much than just tests. They become some sort of general specification, describing  “units of functionality” for your application.

When refactoring and optimizing your code, you may restructure your code without any risks, since all your modifications are now verifiable. Unit tests ensure that there are no technical or functional regressions and furthermore the coherence of behavior. They validate that your application will always behave in the same way, if they are executed with success.

Additionally if you combine TDD with Extreme Programming (XP) and pair programming, you obtain a code with a very high degree of quality.

The next blog post in the series is going to talk about some the new features in Visual Studio 2012, that allow you to apply TDD quickly and easily, stay tuned!


Share/Save/Bookmark

Thursday, December 1, 2011

[Publication] Article in French Programmez Magazine on Design By Contract and Code Contracts using C# 4.0

You can find an article of 4 pages concerning Design By Contract and more specific Code Contracts using C# 4.0 in the French Programmez magazine No.147 written by me and Fathi Bellahcene.

image

First Page and Second Page (low resolution)

Third Page and Fourth Page (low resolution)

The article is written in French but as always I will write some English articles on my Blog in the next weeks. So stay tuned if you are interested in getting to know Code Contracts in C# 4.0 and how it may help you to improve the quality of your code .

You can find the source code here:
http://designbycontract.codeplex.com


Share/Save/Bookmark

Thursday, April 28, 2011

[C# and Language] DevLabs Website

Microsoft is working constantly on new incubation projects to extend existing language features and add new ones. Some of the early versions of those new features can be tested on the DevLabs website. When they are considered to be accepted and they have finished their incubation period they are moved to the respective product sections (as it was done for the Reactive Extensions) or are directly integrated into the corresponding products such as Visual C#.

image

Currently there are the following incubation projects available:

  • TC Labs: Solver Foundation (build and solve real optimization models)
  • TC Labs: TPL DataFlow (extensions to the .NET 4.0 TPL addressing additional scenarios)
  • TC Labs: Dryad (process large volumes of data in many types of applications and enable LINQ on HPC systems)
  • TC Labs: Sho (connect IronPython scripts with compiled .NET code for fast and flexible prototyping)
  • Doloto (AJAX Download Time Optimizer)
  • Code Contracts (extensions to the existing .NET 4.0 version)
  • Axum (parallel applications development based on the actor model)
I am personally currently looking into TPL DataFlow, CodeContracts and Axum (since some time already) and will take some time to give you feedback on my experience in the next weeks.


Share/Save/Bookmark

Tuesday, June 23, 2009

[DevLabs] DevLabs – Microsoft Innovation Projects

Microsoft provides its latest and most inventive ideas to the public in the form of experimental innovation projects on the DevLabs Homepage, that can be found under http://msdn.microsoft.com/devlabs.

The current projects are:

  • Axum (Safe and productive parallel programming model for .NET)
  • Chess (Finding and Reproducing Heisenbugs in Concurrent Programs)
  • Code Contracts (Language-agnostic coding assumptions in .NET)
  • Pex (Automated White Box Testing for .NET)
  • Microsoft Popfly (Creating and sharing games the easy way)
  • Small Basic (Learning a programming language the small and easy way)

Axum is especially interesting since it provides a whole new language approach to parallel programming, while Chess assures that Race conditions are identified and handled correctly.

Code Contracts and Pex aid in delivering robust and highly tested applications since they assure that functions are working as expected.

You may download, install and evaluate the projects to be prepared for their future releases and to participate in their development.


Share/Save/Bookmark