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