Running unit tests from a .proj file using MSBuild

I want to run unit tests using MSBuild. This is how I call msbuild today:

msbuild MySolution.sln

Instead, I want to use the MSBuild project file named "MyBuild.proj" as follows:

 <?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 this, the command immediately ends, and the build does not even happen. I am afraid that I should miss something very obvious, as I am new to MSBuild.

I suppose I really have 2 questions:

  • Why doesnโ€™t this even create my solution.
  • Is the "TestContainer" element correct for performing my tests.

Thanks!

+4
source share
1 answer

You didnโ€™t set anything to actually do anything, for your build goal you need to call the msbuild task, your example will look like this:

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

this indicates which projects you want to create msbuild. See http://msdn.microsoft.com/en-us/library/vstudio/z7f65y0d.aspx for more details and parameters that are required.

This is the first part.

Regarding part 2? what testing framework are you using? If you use mstest id, try running the mstest.exe command on the msbuild command line to run it and run the tests. Example here: http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/cb87a184-6589-454b-bf1c-2e82771f c3aa

+4
source

Source: https://habr.com/ru/post/1479620/


All Articles