# If unit Test Fail do something THEN Fail

**URL:** https://www.finalbuilder.com/forums/t/if-unit-test-fail-do-something-then-fail/5275
**Category:** Discussion
**Created:** [November 18, 2014, 9:13am UTC](https://www.finalbuilder.com/forums/t/if-unit-test-fail-do-something-then-fail/5275 "2014-11-18T09:13:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![haggy](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/h/edb3f5/32.png) [@haggy](https://www.finalbuilder.com/forums/u/haggy)
#### Post date: [November 18, 2014, 9:13am UTC](https://www.finalbuilder.com/forums/t/if-unit-test-fail-do-something-then-fail/5275/1 "2014-11-18T09:13:58Z")

</div>

Hi  
  
I would like to run some actions if unit tests are failing. And then let the test fail.  
currently i got a Try catch and in catch i make these actions but then the build wouldn’t fail, right?  
  
How can i achieve to rune some actions if unit tests fail and then let the build fail  
  
further more how can i get a list of the failed tests to pass them to the following action?

---

<div class="post-metadata">

### Author: ![peter.toms](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/df788c/32.png) [@peter.toms](https://www.finalbuilder.com/forums/u/peter.toms)
#### Post date: [November 19, 2014, 2:02am UTC](https://www.finalbuilder.com/forums/t/if-unit-test-fail-do-something-then-fail/5275/2 "2014-11-19T02:02:09Z")

</div>

Hi Haggy, thank you for posting. &nbsp;  
  
This is achievable by setting up a try / catch around your tests within a stage, and keeping the default stage gate conditions (which are set to fail a build if one or more unit tests fail or error). &nbsp;I have setup a quick project below to demonstrate.  
  
1. Setup your stages (in this example we have three stages however your situation may be different)  
  
 ![](https://www.finalbuilder.com/forums/uploads/default/original/2X/d/d066ae29d2c676ec34638500b45578a54ee39dd1.png)  
  
2. Build your solution (in this example I use the Visual Studio build runner within the build stage)  
  
 ![](https://www.finalbuilder.com/forums/uploads/default/original/2X/3/3da63073a952a160e3f7be7547a5ea2e7b307a03.png)  
  
3. Setup your tests within a try / catch (here I am running a simple delay action within the catch, however you may have any actions depending on your requirements). Note the indents which are controlled from the stage action bar.  
  
 ![](https://www.finalbuilder.com/forums/uploads/default/original/2X/4/4ea198246a66ab7d3777337d389d6fe32b02eb44.png)  
  
4. Ensure your stage gate conditions are set correctly. These are accessed by clicking on the blue rectangle next to the stage (shown in step 1 above). You can place your own variables or use [expression objects](http://wiki.finalbuilder.com/display/continua/Expression+Objects) in [stage gates](http://wiki.finalbuilder.com/display/continua/Stages#Stages-EditingStageGates).

 ![](https://www.finalbuilder.com/forums/uploads/default/original/2X/3/3e403efe77d28a98874498890d93c5df19ebbd53.png)  
  
We don’t currently have a feature that pass failed tests onto other actions (not a usecase we have seen yet, mainly due to the fact that Unit tests are represented within the Unit Test tab of a build). If you are using MSTest / NUnit or DUnitX as your test running you have access to the full results of the tests (in the file you specified within the action, eg $Workspace$\Output\testresult.xml).Below is my Nunit test action from the above example (I used the filename: $Workspace$\Output\testresults.xml):  
  
 ![](https://www.finalbuilder.com/forums/uploads/default/original/2X/9/925eea423768940e35736b43d61eef78beb7487f.png)
