7

I have a post-test script that I'd only like to run once all the tests has successfully passed. The post-test script is a PowerShell script, but I don't know how to detect if any tests failed or not.

I can't change the build process as I'm using TFS Online. I'm also using the TfvcTemplate.12.xaml.

Any help would be greatly appreciated. Thanks in advance.

JD Stuart
  • 547
  • 1
  • 3
  • 13
  • Note: you are free to change the build process template with TFS Online. – Dylan Smith Feb 27 '14 at 05:43
  • 3
    Even if you can edit the template, it's still nontrivial to accomplish. My solution was to add a new IBuildDetail process variable, add the GetBuildDetail activity right after "Run VS Test Runner" (outputting the BuildDetail object to the variable), and finally use BuildDetail.TestStatus as a condition for the post-test powershell script. – Mike Asdf Mar 24 '14 at 22:12
  • I'm surprised there's no simple answer to this. It's trivial in other systems like TeamCity... in fact it's the default behavior to NOT run any more build steps if the tests fail. – dprothero Jul 23 '15 at 19:59
  • Looks like there is a solution here: http://stackoverflow.com/questions/26809062/how-do-i-detect-if-the-test-run-was-successful-in-a-team-build-2013-post-test-sc – dprothero Jul 24 '15 at 14:18
  • The comment above by @MikeAsdf should be an answer here. I already make use of the IBuildDetail in my template based on TfvcTemplate.12 so it was simply a matter of changing the Enabled property on the post-test activity to BuildDetail.TestStatus <> BuildPhaseStatus.Failed. In my case I want the script run in all cases except test failure. – harlam357 Jun 27 '16 at 16:18
  • You can't add a build step? – AussieJoe May 10 '18 at 20:11

1 Answers1

0

If you are using vstest.console or any kind of testing tool where there's output, you can capture the output in a PowerShell variable and iterate through the results.

$Results |? {$_ -match "Failed: 0"} |% {$Failed = $false}