13

是否有可能通配符testcontainer值傳遞到命令行mstest.exe而不是手動硬編碼多個testcontainer值?如通配符測試容器爲mstest。 exe文件

Mstest.exe/testcontainer:測試 .dll文件

我想手動調用MSTEST我們TFS 2012升級template.xaml建立processso tthat它就像一個自動發現方式類似於運行測試在默認情況下template.xaml

如果沒有這哪是從給定的起始文件夾寫入一個蝙蝠腳本來遍歷文件夾?

回答

24

MSTest對於testcontainer沒有采用通配符參數(look here for a reference on the command line options)。然而,可以採取多/ testcontainer參數,如下所示:

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

你將不得不提供這些參數的另一種方式。這可以使用批處理文件來完成,但是MSBuild可能是這更好的選擇:

<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> 

(與感謝https://stackoverflow.com/a/2770682/62662的變換)

保存我到一個文件(testall.proj),並運行它與MSBuild testall.proj,或創建一個批處理文件爲您運行它。

另請注意,mstest會將所有提供的testcontainers加載到一個應用程序域中,因此它們需要支持相同的平臺目標(任何cpu,x86,x64)。

+0

我想變換可以通過僅僅霎那身份進行簡單每個組件的屬性。我也遇到了路徑問題(測試DLL並不直接位於我的目標文件存儲位置),這也解決了這個問題。 '/ testcontainer:"%(身份)"','「)」 /> –

3

也可以使用CMD文件收集通過通配符容器到一個單一變量,然後用這個變量擴充運行MSTEST:

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% 
+1

有沒有最大長度的命令行?如果有數百個測試DLL,它會繼續工作嗎? –