从 powershell 调用时 Mstest 命令间歇性失败

Mstest command failing Intermittently when calling from powershell

function LoginNormal
{
    $MSTestCall = "C:\Program Files (x86)\Microsoft Visual Studio    14.0\Common7\IDE\MSTest.exe"
    $MSTestArguments = @('/testsettings:C:\PerformanceTests\Local.testsettings')
    $file="C:\LoadTestsQA\Login_Normal.loadtest"
    $MSTestArguments += "/TestContainer:" + $file
    & $MSTestCall $MSTestArguments
}
function LoginPeak
{
    $MSTestCall = "C:\Program Files (x86)\Microsoft Visual Studio     14.0\Common7\IDE\MSTest.exe"
    $MSTestArguments = @('/testsettings:C:\PerformanceTests\Local.testsettings')
    $file="C:\LoadTestsQA\Login_Peak.loadtest"
    $MSTestArguments += "/TestContainer:" + $file
    & $MSTestCall $MSTestArguments
}
LoginNormal
LoginPeak

此 powershell 脚本在 MSTest 的帮助下使用 powershell 执行 Visual studio 在线负载测试。 即使这个脚本给了我想要的输出,有时任何一个函数都会失败并且输出如下:

Starting execution...
Connecting to https://mytestsite.visualstudio.com
Initializing
One or more errors occurred.
Failed

Final Test Results:
Results Top Level Tests
------- ---------------
Not Executed c:\performancetests\loadtestsqa\login_normal.loadtest
0/1 test(s) Passed, 1 Not Executed

不知何故,我设法找到了解决办法。由于此函数无法间歇性地在 visual studio 团队服务中创建负载测试,因此我将再次调用相同的函数,直到它创建负载测试。

function LoginNormal
    {
    $MSTestCall = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe"
    $MSTestArguments = @('/testsettings:C:\PerformanceTests\Local.testsettings')
    $file="C:\LoadTestsQA\Login_Normal.loadtest"
    $MSTestArguments += "/TestContainer:" + $file
    Trap {Continue} Stop-Transcript | out-null
    Start-Transcript -path C:\test\s.txt -append
    & $MSTestCall $MSTestArguments
    Stop-Transcript
    $c=Select-String -Path C:\test\s.txt -SimpleMatch "Test Run Failed."
 checkStringLoginNormal($c)
}
function checkStringLoginNormal($arg1)
{
    if(-Not $arg1)
    {
        Start-Sleep -s 60
        Remove-Item C:\test\s.txt
        LoginPeak
    }
else
    {
    Start-Sleep -s 60
    Remove-Item C:\test\s.txt
    #calls the LoginNormal function until the text file contains the text "Test Run Failed."
     LoginNormal 
    }
}
LoginNormal