Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wildcard test containers to mstest. exe

Is it possible to pass wildcard testcontainer values to the command-line mstest.exe rather than manually hardcoding multiple testcontainer values? Such as

Mstest.exe /testcontainer:tests.dll

I'm wanting to manually invoke mstest in our tfs 2012 upgrade template.xaml build processso tthat it behaves like a autodiscovery way similar to running tests in default template.xaml

If not could this be written into a bat script to loop through folders from a given start folder?

like image 321
Kyle Avatar asked Dec 02 '12 12:12

Kyle


People also ask

How do I run MSTest from command line?

To access the MSTest tool, add the Visual Studio install directory to the path or open the Visual Studio Group from the Start menu, and then open the Tools section to access the Visual Studio command prompt. Use the command MSTest from the command prompt.

Where is MSTest installed?

The default path is: C:\Program Files (x86)\Microsoft Visual Studio <version>\Common7\IDE. Currently MSTest distributed with Microsoft Visual Studio/Visual Studio Test Agent 2015 is supported.

What is VSTest console?

VSTest. Console.exe is the command-line tool to run tests. You can specify several options in any order on the command line. These options are listed in General command-line options. The MSTest adapter in Visual Studio also works in legacy mode (equivalent to running tests with mstest.exe) for compatibility.


2 Answers

MSTest doesn't take a wildcard parameter for the testcontainer (look here for a reference on the command line options). It can however take multiple /testcontainer arguments, as follows:

mstest.exe /testcontainer:a.test.dll /testcontainer:b.tests.dll

You will have to supply these parameter another way. This can be done using a batch file, but MSBuild may be a better choice for this:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="RunMSTest">

<ItemGroup>
    <TestAssemblies Include="**\*Tests.dll"/>
</ItemGroup>

<Target Name="RunMSTest">
    <Exec Condition=" '@(TestAssemblies)' != ''"
          Command="Mstest.exe @(TestAssemblies ->'/testcontainer:&quot;%(RecursiveDir)%(Filename)%(Extension)&quot;', ' ')"
          />
</Target>

</Project>

(with thanks to https://stackoverflow.com/a/2770682/62662 for the transform)

Save i to a file (testall.proj), and run it with MSBuild testall.proj, or create a batch file to run it for you.

Also note that mstest loads all supplied testcontainers in one application domain, so they will need to support the same platform target (any cpu, x86, x64).

like image 86
oɔɯǝɹ Avatar answered Oct 02 '22 05:10

oɔɯǝɹ


It is also possible to use cmd file to collect containers by wildcard into a single variable, and then run mstest with this variable expanded:

call "%VS100COMNTOOLS%vsvars32"
@setlocal enabledelayedexpansion enableextensions
@set list=
@for %%x in (.\Bin\Debug\*Test.dll) do set list=!list! /testcontainer:%%x
@set list=%list:~1%

mstest %list%
like image 3
Alexander Avatar answered Sep 30 '22 05:09

Alexander