Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling MSTest with Powershell

I am trying to execute from powershell the Visual Studio's tool MSTest with no success:

$testDLL = "myTest.dll"
$mstestPath = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe"    
$arguments = " /testcontainer:" + $testDLL + " /test:UnitTest1"

Invoke-Expression "$mstestPath $arguments"

I get this error: "The term 'x86' is not recognized as the name of a cmdlet, function,..." Any idea? Thanks.

Edit:

Ok, the problem was solved using "&" instead "Invoke-Expression" and creating separated variables for each argument, it doesn't work for me just using both in one var:

$testDLL = "myTest.dll"
$mstestPath = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe"    
$argument1 = "/testcontainer:" + $testDLL
$argument2 = "/test:UnitTest1"

& $mstestPath $argument1 
like image 893
Jero Lopez Avatar asked Jun 04 '13 09:06

Jero Lopez


1 Answers

I'd recommend using the & operator in the case (see comment David Brabant).

However, if you must use Invoke-Expression you could convert $mstestPath to its shortpath equivalent.

$testDLL = "myTest.dll"
$fs = New-Object -ComObject Scripting.FileSystemObject
$f = $fs.GetFile("C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe")
$mstestPath = $f.shortpath   
$arguments = " /testcontainer:" + $testDLL + " /test:UnitTest1"
Invoke-Expression "$mstestPath $arguments"
like image 56
jon Z Avatar answered Nov 09 '22 15:11

jon Z