Using VSTest to run unit test cases instead of MSTest

前端 未结 3 521
北荒
北荒 2021-01-31 12:08

I have an x64 platform C# solution(VS2012) on a TFS2010 server. I have attached a unit test project (also x64) to this solution and created a build definition. When I queue the

3条回答
  •  悲哀的现实
    2021-01-31 12:46

    Executing unit tests through VSTest and publishing the test results through MSTest gave me a successful outcome. Given below is the Powershell script:

    #  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
    

提交回复
热议问题