使用VSTest运行单元测试用例而不是MSTest

Ark*_*oid 12 c# tfs xaml build-process visual-studio-2012

我在TFS2010服务器上有一个x64平台C#解决方案(VS2012).我已将一个单元测试项目(也是x64)附加到此解决方案并创建了一个构建定义.当我对构建进行排队时,它会成功,但不会执行单元测试用例.这是因为MSTest是一个32位应用程序.因此,我决定自定义默认构建过程模板(DefaultTemplate.xaml)以调用VSTest(VSTest.console.exe)而不是MSTest.这非常复杂,我无法为VSTest的工具箱添加构建活动.

有没有人做过这种定制?我还考虑过配置.runsettings文件等其他方法.我们是否有可以添加到.runsettings文件中的VSTest适配器接口?

Ark*_*oid 17

通过VSTest执行单元测试并通过MSTest发布测试结果给了我一个成功的结果.以下是Powershell脚本:

#  Get the UnitTest Binaries
$files = Get-ChildItem $TestAssembliesDir\*est*.dll

#  VSTest.console.exe path
$VSTestPath = 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe'

#  MSTest path
$MSTestpath = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe"
#  Loop through the test assemblies and add them to the VSTestFiles

$VSTestFiles = ''  
foreach($file in $files)  
{   
    $VSTestFiles += "`"$file`"" 
    $VSTestFiles += " "
} 

#  Run the UnitTests using VSTest 
&$VSTestPath  $vstestplatform "/Framework:Framework45" "/InIsolation" $VSTestFiles "/logger:trx"

#  Get TRX files
$TrxFilesList = Get-ChildItem $TestResDir\*.trx
$TrxFiles = ''  
$loop = 1
foreach($file in $TrxFilesList)  
{   
    $TrxFiles = "$file" 
    # copy the trx file into a space-less named trx
    $newTrxFileName = "$BuildUri" + "_" + "$loop" + ".trx"

    copy-item $TrxFiles -destination $TestResDir\$newTrxFileName

    $loop = $loop + 1
    $newTrxFile += "$TestResDir\$newTrxFileName"
    $newTrxFile += " "
} 

#  specify MSTest arguments 
$mspubl = "/publish:"+$TeamProjColUri
$msteampr = "/teamproject:" + $TeamProj
$mspublbuild = "/publishbuild:" +$BuildUri
$mspubresfile = "/publishresultsfile:" +"`"$newTrxFile`""
#Publish test results through MSTest
&$MSTestpath  $mstestplatform $flavor $mspubl $msteampr $mspublbuild $mspubresfile
Run Code Online (Sandbox Code Playgroud)