I need to be able to launch a loadtest run using powershell
Currently, using below code
$test = "D:\LPT\abc.loadtest"
$fs = New-Object -ComObject Scripting.FileSystemObject
$f = $fs.GetFile("C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\mstest.exe")
$mstestPath = $f.shortpath
$arguments = " /testcontainer:" + $test + " /testsettings:D:\LPT\RemoteExecution.testsettings" + " /resultsfile:D:\LPT\TestResults\Results.trx"
Invoke-Expression "$mstestPath $arguments"
after running this, in the ps console it shows Loading
D:\LPT\abc.loadtest...
Starting execution...
But in Visual studio, in test results
It is shown this way with a failure. Is there a way to run loadtest using powershell + cmd line successfully ?
using VS2017, PS4
Initially I read somewhere that adding this would be helpful:
[DeploymentItem("Microsoft.Practices.Prism.dll")]
After adding this the code ran fine, the loadtest started running but still i kept getting the error
"Test Run deployment issue: The assembly or module log4net directly or indirectly referenced by the test container 'd:\lpt\bin\release\YYY.dll"
I think the issue mainly was with how the arguments were passed. A colleague suggested that the $Arguments is a very sensitive variable to be passing and that it should be written carefully
Then the arguments were written more properly & $Arguments was changed to this, and the [DeploymentItem] was removed, but even without this code snippet the below code works:
Launching LoadTest using Invoke-Expression
$FileSystem = New-Object -ComObject Scripting.FileSystemObject
$File = $FileSystem.GetFile( $MsTestPath )
$MsTestPath = $File.shortpath
$Arguments = "/testcontainer:$TestMethodPath /testsettings:$TS /resultsfile:$Res"
Invoke-Expression "$MsTestPath $Arguments"
Finally, a better way to track the loadtest from the start to the end is by using Start-Process, so the below code worked perfectly for me and returns 0 if the loadtest run is successful or any other value if any issue occurs:
Launching LoadTest using Start-Process
$FileSystem = New-Object -ComObject Scripting.FileSystemObject
$File = $FileSystem.GetFile( $MsTestExePath )
$MsTestPath = $File.shortpath
$Arguments = "/testcontainer:$TestMethodPath /testsettings:$TestSettingsPath /resultsfile:$ResultsFile"
$Result = ( Start-Process $MsTestExePath -ArgumentList $Arguments -NoNewWindow -Wait -PassThru )
$Result.ExitCode - provides pass/fail info