Visual Studio Express does not support the test driven developers. The Express editions do not have any integrated testing framework like MSBuild and you cannot add-in one, as addins/plugins are disallowed. Also there is a limitation to attach the debugger to a process, so you cannot easily debug an external test runner like Gallio or NUnit.

Fortunately, there are some workarounds. Here is the summarized result of my research on the topic of running and debugging tests with Visual Studio Express.

  • To run tests you can
    • use a standalone test runner and execute it against an assembly with your tests;
    • configure the Visual Studio to execute a test runner through the Tools menu like Martijn Dijksterhuis suggested.
  • To debug tests you can
    • convert your test library project into console or Windows Form application and point it to your favorite test runner as it shown in Steve Dunn's blog post;
    • manually edit the project file to specify a test runner as external program in the Start Action for your test assembly in a similar way as Pål Fossmo or Jeremy Tammik described.

I prefer the last workaround, modification of the msbuild project file. The following piece of .csproj file allows me to integrate MbUnit test runner into Microsoft Visual C# 2010 Express.


<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <DebugSymbols>true</DebugSymbols>
  <DebugType>full</DebugType>
  <Optimize>false</Optimize>
  <OutputPath>bin\Debug</OutputPath>
  <DefineConstants>DEBUG;TRACE</DefineConstants>
  <ErrorReport>prompt</ErrorReport>
  <WarningLevel>4</WarningLevel>
  <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
  <StartAction>Program</StartAction>
  <StartProgram>$(MSBuildProjectDirectory)\..\Tools\MbUnit\Gallio.Echo.exe</StartProgram>
  <StartArguments>$(MSBuildProjectDirectory)\$(OutputPath)\$(AssemblyName).dll /runner:IsolatedAppDomain /report-type:Text /show-reports</StartArguments>
  <StartWorkingDirectory>$(MSBuildProjectDirectory)\$(OutputPath)</StartWorkingDirectory>
</PropertyGroup>

The StartAction, StartProgram, StartArguments and StartWorkingDirectory are related to the Start Action feature hidden in the Express edition. The StartProgram specifies the console test runner, Gallio Echo; the StartArguments property includes what to test, and how to run the test runner (note the "/runner:IsolatedAppDomain" argument that allows to debug the tests) and report type.

It is also possible to use GUI test runner, Gallio Icarus. Just for debugging it is necessary to manually set the IsolatedAppDomain (Gallio Control Panel > Preferences tab > Icarus > Runner > Test Runner Factory) as it is not possible to specify through the command line.


<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  ...
  <StartAction>Program</StartAction>
  <StartProgram>$(MSBuildProjectDirectory)\..\Tools\MbUnit\Gallio.Icarus.exe</StartProgram>
  <StartArguments>$(MSBuildProjectDirectory)\$(OutputPath)\$(AssemblyName).dll</StartArguments>
  ...
</PropertyGroup>

Press F5 and enjoy this free solution.

 

Updates

  1. Removed spaces in XML values. (20.4.2011)

Comments

Andy Creigh wrote 4/18/2011 at 8:37 PM Hi Yauhen,
Thanks for posting this, I had been looking all over to find how to run Gallio in VS Express. Just one issue, when I copied the project file contents from the example above I ended up with spaces between the XML tags and this caused Visual Studio to show an error saying 'The working directory does not exist'. Once I figured this out by comparing it to the example you sent me the problem was obvious and easily rectified. Just ensure that there are no spaces between the tag delimiters and the values, e.g.
<StartArguments>$(MSBuildProjectDirectory)\$(OutputPath)\$(AssemblyName).dll</StartArguments>

It's all working nicely now.
Cheers,
Andy
Yauhen wrote 4/20/2011 at 9:02 AM Andy,
Thank you for pointing out to the issue. I updated the samples.
Alex Green wrote 9/4/2011 at 6:47 PM And for NUnit:


  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files\NUnit 2.5.10\bin\net-2.0\nunit.exe</StartProgram>
    <StartArguments>$(MSBuildProjectDirectory)\$(OutputPath)\$(AssemblyName).dll</StartArguments>
    <StartWorkingDirectory>$(MSBuildProjectDirectory)\$(OutputPath)</StartWorkingDirectory>
  </PropertyGroup>