powershellvstest.console.exe

Vstest.console in powershell and Action Based on results


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

Solution

  • 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.