0

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

enter image description here

It is shown this way with a failure. Is there a way to run loadtest using powershell + cmd line successfully ?

using VS2017, PS4

Anu7
  • 77
  • 1
  • 17
  • The ". trx" file is just text (xml). What does it contain? I expect it includes an error message or similar. – AdrianHHH Aug 23 '19 at 17:55
  • @AdrianHHH it says "Result: Not Executed" ALSO the xml file says "Test Run deployment issue: The assembly or module XXX directly or indirectly referenced by the test container 'd:\lpt\bin\release\YYY.dll' was not found. - but they're available. – Anu7 Aug 26 '19 at 04:45
  • 1
    The message says that something referenced by YYY.dll was not found, that can include wrong versions. There are several questions here and in other websites about DLL not found and ways to debug the problem. There is a Microsoft utility to monitor DLL loading (I have forgotten its name and cannot easily search right now). – AdrianHHH Aug 26 '19 at 06:18
  • ok ill check those again once ( i did come across them but found that my dll was intact, only i didnt know the version could be an issue) thank you ! – Anu7 Aug 26 '19 at 07:36
  • You might find [fuslogvw](https://learn.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer) useful. – AdrianHHH Aug 26 '19 at 16:51

1 Answers1

0

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
Anu7
  • 77
  • 1
  • 17