0

I'm trying to run some functional unit tests using vstest.console in PowerShell, and if any tests fails, I would perform a certain action (in this case, it would be rolling back an installation). How do I go about doing that.

Here is the current content of the PowerShell script I have.

$command = "<path_to_vstest_directory>\vstest.console.exe"
$arguments = @('<test dll>', '/Tests:"<name_of_specific_test_to_run>"')
&$command $arguments
  • Automatic variable `$LASTEXITCODE` contains the exit code of the most recently executed external program; `exit $LASTEXITCODE` allows you to use that exit code as your script's. – mklement0 Apr 16 '20 at 01:22

1 Answers1

0

You can use the Start-Process cmdlet to gain some control over the executed process:

$command = "<path_to_vstest_directory>\vstest.console.exe"
$testDll = "Path\with space\test.dll"
$testName = "name_of_specific_test_to_run"
$process = Start-Process $command -ArgumentList "`"$testDll`" /Tests:`"$testName`"" -PassThru -Wait

After that, you can evaluate the exit code stored in $process.ExitCode. You have also the possibility to redirect stdout and stderr, if needed.

stackprotector
  • 10,498
  • 4
  • 35
  • 64