VsTestRunner Execution(Unit Test) execution using Powershell

http://rsinvestgroup.com/wp-json/oembed/1.0/embed?url=http://rsinvestgroup.com/es/productos/ #Test Execution
[cmdletBinding()]
param
(
[parameter(Mandatory = $true)]
$TestDir, #relative to bamboo working directory
[parameter(Mandatory = $true)]
$VstestConRunner,
[parameter(Mandatory = $true)]
$TestPattern,
[parameter(Mandatory = $true)]
$Logger,
[parameter(Mandatory = $false)]
$RunSettingFile

go here )
<#$OutDir = “C:\BambooBld\SVE-SVC-JOB1\bin”
$TestPattern = “*.DS.ServiceEdge.SPS.REST.Tests*.dll”
$VstestConRunner = “C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\..\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe”
$Logger = “trx”
$RunSettingFile = “C:\Soft\SVE.runsettings”
$TestAssList = $null

go $TestAssList | Out-File “C:\testlist.log”
#$TestAssList =$null
#$TestAssList = “””C:\BambooBld\SVE-SVC-JOB1\bin\SPS.REST.Tests\REST.Tests.dll””” + ” ” + “””C:\BambooBld\SVE-SVC-JOB1\bin\Tests\Core.Tests.dll””” + ” ” + “”#>
Write-Host $VstestConRunner
Get-ChildItem $TestDir -Include $TestPattern -Recurse | ForEach-Object { $TestAssList += “””$_””” +” “}
Write-Host $TestAssList
if (($TestDir -eq $null) -or ($TestDir -eq “”)) { throw “Test Directory CANNOT be blank!” }
if (($VstestConRunner -eq $null) -or ($VstestConRunner -eq “”)) { throw “VsTest console runner CANNOT be blank!” }
if (($TestPattern -eq $null) -or ($TestPattern -eq “”)) { throw “test pattern CANNOT be blank!” }
if (($Logger -eq $null) -or ($Logger -eq “”)) { throw “Logger CANNOT be blank!” }

try
{
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.CreateNoWindow = $true
$pinfo.UseShellExecute = $false
$pinfo.RedirectStandardOutput = $true
$pinfo.RedirectStandardError = $true
$pinfo.FileName = “””$VstestConRunner”””

cheap aciphex if($RunSettingFile -eq $null -or $RunSettingFile -eq “”)
{
$pinfo.Arguments = $TestAssList + ” ” + “/Logger:$Logger” + ” ” + “/Platform:X64”
Write-Host ‘Executing’ $VstestConRunner $TestAssList “/Logger:$Logger” “/Platform:X64″
}
else
{
$pinfo.Arguments = $TestAssList + ” ” + “/Settings:””$RunSettingFile””” + ” ” + “/Logger:$Logger” + ” ” + “/Platform:X64”
Write-Host ‘Executing’ $VstestConRunner $TestAssList “/Settings:$RunSettingFile” “/Logger:$Logger” “/Platform:X64”
}
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $pinfo
[void]$process.Start()
$output = $process.StandardOutput.ReadToEnd()
$process.WaitForExit()
Write-Host $output
$startIndex = $output.IndexOf(“Failed:”)
$charArray = [char[]]$output.Substring($startIndex) #putting the substring in an array to fetch the location of .(period)
$i = 0
While($charArray[$i] -ne “.”) { $i++}
[int32]$FailedCount = $output.Substring([int32]$startIndex + 7, [int32]$i -7)#start the index to fetch substring after Failed: and number of char just before period “.”
if($FailedCount -gt 0)
{
Write-Error “Test Run Failed. Failed count is $FailedCount”
throw “Test Run Failed.”
exit 500
}
}
catch [Exception]
{
$_.Exception.GetType().FullName, $_.Exception.Message
Write-Error “Test execution failed”
}

Leave a Reply

Your email address will not be published. Required fields are marked *