Quick tip: How to do TDD/BDD and debug unit tests with Visual Studio Express editions

by Tom 25. October 2011 07:47

Introduction

This article will show you how you can do TDD/BDD with Visual Studio Express editions. While most people say it is not possible, it is actually pretty easy.

Prerequisites

How do you do it ?

  1. Open your project in Visual Studio Express
  2. Add a new class project, name it [Project].Specs
  3. Add a reference to the testlib you want to use with Nuget (Right click on the project references and choose "Manage Nuget Packages") - I use MSpec a lot.
  4. Start AutoTest.Net, after you configured it for the testlib (adjust AutoTest.config file for the correct testrunner)
  5. Start writing your specs
  6. Every time you save a file, your project is compiled and your tests are ran
That is all you need; pretty simple actually, is it not ?
There is also the possibility to have notifications and stuff like that, but I currently do not use them.

But wait, what if I need to debug a test ?

As I sometimes only do integration tests, I need the ability to debug these tests. But there is no option to do this in the Express editions, or is there ?

Well, this took me a bit longer to find out, but once you know how to do this it is pretty easy:
  1. Right click on your spec project, and choose "Unload project"
  2. Right click the unloaded project and choose "edit [xxx].Specs.csproj", you will see an XML
  3. Find the matching PropertyGroup for your configuration (usually <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> )?
  4. Add the following child items in the property group (I used mspec as an example here):
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
          ....
          <StartAction>Program</StartAction>
          <StartProgram>C:\Users\Public\Documents\OudePc\Projecten\Org.NerdBeers\src\Org.NerdBeers\packages\Machine.Specifications.0.4.24.0\tools\mspec-x86-clr4.exe</StartProgram>
          <StartArguments>Org.Nerdbeers.specs.dll</StartArguments>
          <StartWorkingDirectory>C:\Users\Public\Documents\OudePc\Projecten\Org.NerdBeers\src\Org.NerdBeers\Org.NerdBeers.Specs\bin\Debug</StartWorkingDirectory>
    </PropertyGroup>
  5. Save and close the .csproj file
  6. Right click on the project and reload it
  7. Set a breakpoint in the test you want to debug
  8. Right click again on the project, and.....
  9. ... you can now choose "Debug this project"  !!!

Final words

While this approach takes a few minutes to setup, it is definetely not that hard to do. In fact, I just copy the test exes and settings over from another project whenever I need to do it a second time on the same machine. At least this approach will allow you to do proper TDD/BDD with the Express editions of Visual Studio.

 

Bookmark and Share

About Tom

Tom Janssens op LinkedIn

Tom Janssens op twitter

Core bvba RSS

 

Tom Janssens is an independent freelance ICT consultant that has been "into computers" ever since the age of 7.

Typing source code from a book evolved into exploring the limits of coding in procedural, assembly and object-oriented languages.
As he matured in software coding, he started focussing on the problems surrounding software development, and learned that software development is usually about people and interactions first, and about technology second.

Due to his diverse track record he gained insights in a lot of aspects of the software development process. Currently his main focus is on strategic ICT advice, lean product/project development and improving the software development process and architecture.

He avoids ivory-tower-approaches by applying and verifying the applicability of the latest tech buzz in software experiments.

He is also the founder of the following LinkedIn groups:

CQRS Professional
BDD Professional
Asp.Net MVC professional

More info about Tom and his company...


Advertisement

Forget all your SCRUM -, Kanban - and other Agile and Lean certificates

Here is the only true AGILE and LEAN certificate you will ever need:

The Creative Recursive Analysis Process Certificate
(CRAP Certificate for short)

More info can be found at the official CRAP certificate website:
http://bit.ly/CRAPCertificate