# Stopping Test Suite execution if Test Case fails

**URL:** <https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180>\
**Category:** Integrations\
**Tags:** integrations, katalon-studio\
**Created:** [September 12, 2018, 4:17pm UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180 "2018-09-12T16:17:45Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Shchetinin](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alexander\_Shchetinin](https://forum.katalon.com/u/Alexander_Shchetinin)\
**Post date:** [September 12, 2018, 4:17pm UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/1 "2018-09-12T16:17:45Z")

</div>

Is there a way to stop Test Suite execution if one of its Test Cases fails?  
I.e. in case of creating certain elements some crucial part is missing, and then there is no point of reproducing that issue again and again in every Test Case.

---

<div class="post-metadata">

**Author:** ![LaLaTay](https://avatars.discourse-cdn.com/v4/letter/l/3be4f8/32.png) [@LaLaTay](https://forum.katalon.com/u/LaLaTay)\
**Post date:** [September 13, 2018, 6:29am UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/2 "2018-09-13T06:29:29Z")

</div>

Hi Alexander

You can use **com.kms.katalon.core.util.Keywordutil** for this purpose.  
Please use either markErrorAndStop or markFailedAndStop methods.

You can find samples in below link:  
[http://www.sanspantalones.com/2018/02/16/marking-tests-as-passed-failed-or-in-error-using-markfailed-markpassed-markerror-in-katalon-studio/](http://www.sanspantalones.com/2018/02/16/marking-tests-as-passed-failed-or-in-error-using-markfailed-markpassed-markerror-in-katalon-studio/)

---

<div class="post-metadata">

**Author:** ![Alexander\_Shchetinin](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alexander\_Shchetinin](https://forum.katalon.com/u/Alexander_Shchetinin)\
**Post date:** [September 13, 2018, 3:40pm UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/3 "2018-09-13T15:40:02Z")

</div>

I think it stops the failed Test Case only, but the Test Suite keeps executing the rest of Test Cases.

---

<div class="post-metadata">

**Author:** ![Ibus](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@Ibus](https://forum.katalon.com/u/Ibus)\
**Post date:** [September 16, 2018, 7:42am UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/4 "2018-09-16T07:42:25Z")

</div>

If your test cases are dependent on the successful execution of another one, IMHO the right approach is to add them into that test case after the assertion, see [https://docs.katalon.com/display/KD/Call+Test+Case](https://docs.katalon.com/display/KD/Call+Test+Case)

With such design, if the assert fail and the handling is set to ‘Stop on Failure’, the execution will just stop at that point without executing further test-cases.

---

<div class="post-metadata">

**Author:** ![Alexander\_Shchetinin](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alexander\_Shchetinin](https://forum.katalon.com/u/Alexander_Shchetinin)\
**Post date:** [September 20, 2018, 3:22pm UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/5 "2018-09-20T15:22:12Z")

</div>

> [Ibus](http://forum.katalon.com/profile/11075/Ibus) said:
> 
> If your test cases are dependent on the successful execution of another one, IMHO the right approach is to add them into that test case after the assertion, see [https://docs.katalon.com/display/KD/Call+Test+Case](https://docs.katalon.com/display/KD/Call+Test+Case)
> 
> With such design, if the assert fail and the handling is set to ‘Stop on Failure’, the execution will just stop at that point without executing further test-cases.

It might work, but it complicates the scripts structure, it makes that Test Case to work instead of Test Suite

---

<div class="post-metadata">

**Author:** ![Ibus](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@Ibus](https://forum.katalon.com/u/Ibus)\
**Post date:** [September 22, 2018, 7:30am UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/6 "2018-09-22T07:30:45Z")

</div>

well … agreed, makes the structure more complicated.

other option may be … set a global variable based on the result of the first test and execute the others conditionally (sort of 'if $passed then do\_test else println(‘test skipped’)) but this is ugly too, will still call all other testcases but just with a different wokflow

---

<div class="post-metadata">

**Author:** ![Yves\_Beaulieu](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yves\_Beaulieu](https://forum.katalon.com/u/Yves_Beaulieu)\
**Post date:** [September 24, 2018, 4:47pm UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/7 "2018-09-24T16:47:26Z")

</div>

> [Ibus](https://forum.katalon.com/profile/11075/Ibus) said:
> 
> If your test cases are dependent on the successful execution of another one, IMHO the right approach is to add them into that test case after the assertion, see [https://docs.katalon.com/display/KD/Call+Test+Case](https://docs.katalon.com/display/KD/Call+Test+Case)
> 
> With such design, if the assert fail and the handling is set to ‘Stop on Failure’, the execution will just stop at that point without executing further test-cases.

Well I really don’t agree with this approach. It’s important to keep every test cases as simple and clean as possible. There should be a way to stop a whole Test Suite if a Test Case fails. My actual scenario : I need to login to my portal to start my test cases. If the login doesn’t succeed, the rest of the cases will fail for sure. And I need to have that login process in a case by itself (and not in a Setup/Teardown) because I would like to retry my login 3x times before declaring a FAIL (and if I use a Setup/Teardown, it seems like the retry count doesn’t apply).

---

<div class="post-metadata">

**Author:** ![Yves\_Beaulieu](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yves\_Beaulieu](https://forum.katalon.com/u/Yves_Beaulieu)\
**Post date:** [September 24, 2018, 4:53pm UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/8 "2018-09-24T16:53:30Z")

</div>

> [Ibus](https://forum.katalon.com/profile/11075/Ibus) said:
> 
> well … agreed, makes the structure more complicated.
> 
> other option may be … set a global variable based on the result of the first test and execute the others conditionally (sort of 'if $passed then do\_test else println(‘test skipped’)) but this is ugly too, will still call all other testcases but just with a different wokflow

That could help me for a while… do you have an example of code that catches the result of a test case ?

---

<div class="post-metadata">

**Author:** ![Ibus](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@Ibus](https://forum.katalon.com/u/Ibus)\
**Post date:** [September 25, 2018, 5:57am UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/9 "2018-09-25T05:57:26Z")

</div>

that depends on the assert you use in the main test case.

But since that assert, when is failing, it will stop that test case, you can put immediately after something like ‘GlobalVariable.excuteOthers = true’.

If the failure handling is set to STOP\_ON\_FAILURE, when the assert in that main test case will fail, that line won’t be executed and the ‘excuteOthers’ global variable will remain untouched (therefore you have to set it with a default ‘false’)

---

<div class="post-metadata">

**Author:** ![Dennis\_de\_Guzman](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@Dennis\_de\_Guzman](https://forum.katalon.com/u/Dennis_de_Guzman)\
**Post date:** [November 22, 2018, 3:56am UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/10 "2018-11-22T03:56:13Z")

</div>

any update on this concern?

---

<div class="post-metadata">

**Author:** ![Alexandr\_Hladki](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Alexandr\_Hladki](https://forum.katalon.com/u/Alexandr_Hladki)\
**Post date:** [December 6, 2018, 9:04pm UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/11 "2018-12-06T21:04:56Z")

</div>

Hi.

There is a important difference between CallTestCase and “TestSuite with several TestCases”. For example, I have to start after every TestCase @AfterTestCase test listener script. This script inserts TestCase results data into DB through WebService. When I used CallTestCase method, only parent TestCase call @AfterTestCase, but TestCases called by CallTestCase do not call this script. So, I must use TestSuit. But in this case I need to skip other TestCases after one before has fail or error status.

Now, I understand I need to use Global Variable and manual scripting (or @BeforeTestCase???) to stop remaining TestCases execution. Unfortunaltely it’s not elegant solution. Therefore, that is not bad idea to enchance the KATALON with new functionality: stop whole TestSuit after some TestCase will finish with fail or error status.

Regards,

Alex

---

<div class="post-metadata">

**Author:** ![Alexandr\_Hladki](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Alexandr\_Hladki](https://forum.katalon.com/u/Alexandr_Hladki)\
**Post date:** [December 6, 2018, 9:04pm UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/12 "2018-12-06T21:04:56Z")

</div>

Hi.

There is a important difference between CallTestCase and “TestSuite with several TestCases”. For example, I have to start after every TestCase @AfterTestCase test listener script. This script inserts TestCase results data into DB through WebService. When I used CallTestCase method, only parent TestCase call @AfterTestCase, but TestCases called by CallTestCase do not call this script. So, I must use TestSuit. But in this case I need to skip other TestCases after one before has fail or error status.

Now, I understand I need to use Global Variable and manual scripting (or @BeforeTestCase???) to stop remaining TestCases execution. Unfortunaltely it’s not elegant solution. Therefore, that is not bad idea to enchance the KATALON with new functionality: stop whole TestSuit after some TestCase will finish with fail or error status.

Regards,

Alex

---

<div class="post-metadata">

**Author:** ![Rakesh27](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@Rakesh27](https://forum.katalon.com/u/Rakesh27)\
**Post date:** [April 27, 2019, 6:19am UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/13 "2019-04-27T06:19:14Z")

</div>

Even I was not able to find anything to fulfill this requirement. Alternatively You can use the call Test cases in such scenario and can club the depended test cases in one test case. Suppose you have to login and then perform some Test case. you can first create a test case where login will happen and then call the other depended test cases in that same Test case. Make sure you mark the login failure scenario as markfailureandstop method so that it will stop the rest of the execution.

---

<div class="post-metadata">

**Author:** ![sridharsri.cool](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sridharsri.cool](https://forum.katalon.com/u/sridharsri.cool)\
**Post date:** [September 30, 2019, 10:15am UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/14 "2019-09-30T10:15:31Z")

</div>

Hi All,

I came across all the discussions here. However, I have an example scenario wherein TestCase#1 creates a user and Testcase#2 logins to application with that user account. And TestSuite#1 contains Testcase#1 and TestCase#2.

Now when I execute TestSuite#1 and suppose Testcase#1 fails, is there a way to stop executing TestSuite#1 completely. Since it is meaningless to start executing TestCase#2 without user account created(Testcase#1 fails)

Any help is appreciated. Thanks in advance.

Regards,  
Sridhar

---

<div class="post-metadata">

**Author:** ![rodrigocalabretta](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@rodrigocalabretta](https://forum.katalon.com/u/rodrigocalabretta)\
**Post date:** [November 28, 2019, 7:53pm UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/15 "2019-11-28T19:53:40Z")

</div>

I tried with this listener inside my suit:

> ```
> import com.kms.katalon.core.context.TestCaseContext
> import com.kms.katalon.core.model.FailureHandling as FailureHandling
> import com.kms.katalon.core.testcase.TestCase as TestCase
> import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory
> 
> @TearDownTestCase(skipped = true) // Please change skipped to be false to activate this method.
> def tearDownTestCase(TestCaseContext testCaseContext) {
> // Put your code here.
> if(testCaseContext.getTestCaseStatus()=="FAILED"){
> FailureHandling.STOP_ON_FAILURE
> }
> }
> 
> ```

But throws me the following error:  
**Cannot invoke method getTestCaseStatus() on null object**

Anyone could solve this problem in another way?

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [November 29, 2019, 3:13am UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/16 "2019-11-29T03:13:03Z")

</div>

Hi @rodrigocalabretta

Methods annotated with `@TearDownTestCase` don’t accept (by design) a `testCaseContext` object, which is why it is null, and any attempt to call methods on a null object would result in the error you see. Object `testCaseContext` is available only in Test Listeners.

---

<div class="post-metadata">

**Author:** ![rodrigocalabretta](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@rodrigocalabretta](https://forum.katalon.com/u/rodrigocalabretta)\
**Post date:** [November 29, 2019, 1:52pm UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/17 "2019-11-29T13:52:14Z")

</div>

I tried to run that from the @AfterTestCase listener and handle that failure, but the problem is that it didn’t stop the Suit run. Where should I set that failure handling?

---

<div class="post-metadata">

**Author:** ![rodrigocalabretta](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@rodrigocalabretta](https://forum.katalon.com/u/rodrigocalabretta)\
**Post date:** [December 9, 2019, 7:41pm UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/18 "2019-12-09T19:41:22Z")

</div>

Hi guys, I think I have a solution to this.

It’s not my favourite because I have to call this on every SetupTesCase() when I should prefer to stop all the suit immediate but least the test didn’t run

First of all, save the status at the finish test case run creating a string global variable

> **Listerner**
>
> > ```
> > @AfterTestCase
> > def AfterTestCase(TestCaseContext testCaseContext) {
> > if(testCaseContext.getTestCaseStatus()!="PASSED"){
> > GlobalVariable.TestCaseStatus= testCaseContext.getTestCaseStatus();
> > }
> > }
> > 
> > ```

> **Test Suit Script**
>
> > @SetupTestCase(skipped = false)  
> > def setupTestCase() {  
> > // Put your code here.  
> > if(GlobalVariable.TestCaseStatus==“FAILED” || GlobalVariable.TestCaseStatus==“ERROR”){  
> > KeywordUtil.markFailedAndStop(‘ERROR: The previous test fail’)
> > 
> > ```
> > }
> > }
> > 
> > ```

I have to use in the listener that condition because when I mark as Failed or as Error in the previous test that test Fails **RIGHT!** but his status is still **PASSED** when I get testCaseContext.getTestCaseStatus() so that’s the reason (I think maybe this is some error by katalon) 😕

@ThanhTo let me know If you have some improvement in your mind, that’s should be great

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [November 29, 2021, 6:35am UTC](https://forum.katalon.com/t/stopping-test-suite-execution-if-test-case-fails/13180/19 "2021-11-29T06:35:28Z")

</div>

My solution for this years-old problem:

> [@How to let TestCases in a TestSuite to quit once a TestCase failed](http://forum.katalon.com/t/how-to-let-testcases-in-a-testsuite-to-quit-once-a-testcase-failed/60404):
>
> I have published a demo project on GitHub: Problem to solve A topic in the Katalon User Forum wrote: [Stop all test suite if one test case failed](http://forum.katalon.com/t/stop-all-test-suite-if-one-test-case-failed/49629) Hi, there is a way to stop a test suite if one of its cases fails? I need some method or form to stop the suite, does anyone have a solution? Fair enough requirement, I think. Let me assume I have a Test Suite TS1 is comprised with 3 Test Cases: TC1 , TC2 , TC3 . The TC3 runs very long (e.g, 20 minutes). The TC2 normally passes but oc…
