I am trying to run MSTest in Powershell. One of the options to pass is /testcontainer and it can be passed multiple times.
In my script I need to build the option string as I can have many test containers passed to the script, thus this is what I do:
param(
[string[]] $TestContainers = @(
'C:\Users\myuser\MyProject\test\Test1\bin\Debug\Test1.dll',
'C:\Users\myuser\MyProject\test\Test1\bin\Debug\Test2.dll',
'C:\Users\myuser\MyProject\test\Test1\bin\Debug\Test3.dll',
'C:\Users\myuser\MyProject\test\Test1\bin\Debug\Test4.dll'
)
);
$TestContainersOptions = @();
foreach ($TestContainer in $TestContainers)
{
$TestContainersOptions += "/testcontainer:'$TestContainer'";
}
$MSTestPath = "C:\Program...\MsTest.exe"
& $MSTestPath $TestContainersOptions;
When I run the script I get:
Microsoft (R) Test Execution Command Line Tool Version 14.0.23107.0 Copyright (c) Microsoft Corporation. All rights reserved.
The given path's format is not supported. For switch syntax, type "MSTest /help"
What to do?
&should be a string array as well:$TestContainersOptions = $TestContainers|%{"/testcontainer:'$_'"}; & $MSTestPath $TestContainersOptions- Mathias R. Jessen'vs.". You can escape"inside a double-quoted string by entering in twice:"/testcontainer:""$TestContainer"""- Mathias R. Jessen