Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running unit tests from a .proj file with MSBuild

I want to run unit tests using MSBuild. Here is how I invoke msbuild today:

msbuild MySolution.sln

Instead, I want to use an MSBuild project file called "MyBuild.proj" like this:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5" DefaultTargets="Build">
  <Target Name="Build">
    <ItemGroup>
      <SolutionToBuild Include="MySolution.sln" />
      <TestContainer Include="..\Output\bin\Debug\*unittests.dll"/>
    </ItemGroup>
  </Target>
</Project>

And then call this command line:

msbuild MyBuild.proj

For some reason, when I do that the command succeeds immediately and the build doesn't even happen. I fear I must be missing something very obvious as I am new to MSBuild.

I suppose I really have 2 questions:

  1. Why doesn't this even build my solution
  2. Is the "TestContainer" element correct for executing my tests

Thanks!

like image 409
skb Avatar asked May 07 '13 20:05

skb


1 Answers

You havent supplied any task to actually do anything, inside your build target you need a call to an msbuild task, your example becomes:

<Target Name="Build">
   <ItemGroup>
      <SolutionToBuild Include="MySolution.sln" />
      <TestContainer Include="..\Output\bin\Debug\*unittests.dll"/>
    </ItemGroup>
   <MSBuild Projects="@(SolutionToBuild)"/> 
</Target>

this specifies what projects you actually want msbuild to build. See:http://msdn.microsoft.com/en-us/library/vstudio/z7f65y0d.aspx for more details and the parameters it takes.

Thats part one.

As for part 2? what testing framework are you using? If using mstest id try wrapping the commandline mstest.exe in an msbuild exec statement to get it to run and execute the tests. See an example here:http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/cb87a184-6589-454b-bf1c-2e82771fc3aa

like image 122
James Woolfenden Avatar answered Sep 28 '22 10:09

James Woolfenden