Executing VSTest.Console.exe test via Powershell Invoke-Command

时间:2016-04-21 22:16:49

标签: powershell teamcity mstest winrm vstest.console.exe

So I'm trying to kick off test runs via VSTest.Console.exe using Powershell's Invoke-Command. I'm pretty new to powershell, but the script looks like this:

$secpasswd = ConvertTo-SecureString “P@ssword01” -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential (“administrator”, $secpasswd)
$shareName = "testruns"

#Script block to execute on the remote machine
$scriptBlock = {
param($shareName, $testRunId, $myTestContainers, $testCategory)
$localFolder = "c:\$shareName\" + $testRunId
$exePath = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"

$argList = @()
#Add the containers
$myTestContainers.Split(",") | foreach {
    $argList += "`"$localFolder\$_`" "
}

$argList += "/logger:trx"
$argList += "/settings:$localFolder\remote.testsettings"
$argList += "/Platform:x64"
$argList += "/Framework:Framework45"

#Let everyone know whats happening
Write-Output "Args: $argList"

#Do it
& $exePath $argList
}

#Invoke the script block
Invoke-Command -ScriptBlock $scriptBlock -Credential $credentials -ComputerName 10.123.123.12 -ArgumentList testruns, "1.2.3456", "CaiConTest.dll,CsiConTest.dll", ""

After 60 seconds this is returned:

Error: Failed to initialize client proxy: could not connect to test process .
+ CategoryInfo          : NotSpecified: (Error: Failed t... test process .:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName        : 10.123.123.12

Error: There was no endpoint listening at net.pipe://mymachineFQDN/TestExecutor/5208 that could accept the message. This is often caused by an incorrect address or SOAP action. See 
InnerException, if present, for more details.

I've noticed that if I remove the "-Credential $credentials" and run it on the same machine I'm invoking the command on, it runs and we get test results back just fine. What might I be missing here?

1 个答案:

答案 0 :(得分:1)

好的,所以我一直在看这一切都错了。本练习的目的是使用TeamCity metarunner来运行测试。实际上有一个可用的Visual Studio Tests运行器可以完成繁重的工作。只需要退后一步,用新鲜的眼睛看它!