9

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 
2
  • 2
    Related: stackoverflow.com/questions/3868342/… Commented Jun 4, 2013 at 9:56
  • "C:\Program Files (x86)" has a space so add quotes to your string $mstestPath = '"C:\Program Files (x86)\...\IDE\mstest.exe"' Commented Jun 4, 2013 at 17:39

1 Answer 1

9

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"
Sign up to request clarification or add additional context in comments.

2 Comments

nice answer. Do you have any idea how to parse the results?
You export the results out to a trx file using the resultsfile switch: /resultsfile:c:\temp\tests.trx then you can parse the trx file: dbarrowstechblog.blogspot.com.au/2012/08/…'' or c-sharpcorner.com/UploadFile/e06010/read-trx-file-from-C-Sharp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.