# TC getTestCaseStatus == PASSED when SetupTestCase fail

**URL:** <https://forum.katalon.com/t/tc-gettestcasestatus-passed-when-setuptestcase-fail/55076>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [May 24, 2021, 10:42am UTC](https://forum.katalon.com/t/tc-gettestcasestatus-passed-when-setuptestcase-fail/55076 "2021-05-24T10:42:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![patryk.zywert](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/patryk.zywert/32/16103_2.png) [@patryk.zywert](https://forum.katalon.com/u/patryk.zywert)\
**Post date:** [May 24, 2021, 10:42am UTC](https://forum.katalon.com/t/tc-gettestcasestatus-passed-when-setuptestcase-fail/55076/1 "2021-05-24T10:42:15Z")

</div>

I have got a problem, i made simple test listener:  
` if (testCaseContext.getTestCaseStatus() == 'FAILED' || testCaseContext.getTestCaseStatus() == 'ERROR') { WebUI.takeScreenshot() Browser.printLogs() WebUI.refresh() CustomKeywords.'tools.Authentication.login'() }`  
This works as intended, but when my TC fails at @SetupTestCase(because of bad xpath) then testCaseContext.getTestCaseStatus() of this TC gets value “PASSED”. Is this a bug? I thought that it should get IGNORED or ERROR or something like that. Please help, i want to take screen shot when SetupTestCase fails but i don’t want to have that code in TS.

---

<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:** [May 24, 2021, 12:44pm UTC](https://forum.katalon.com/t/tc-gettestcasestatus-passed-when-setuptestcase-fail/55076/2 "2021-05-24T12:44:14Z")

</div>

It seems you are using 2 approaches of `setup/teardown` processing:

1. a Test Listener (a Groovy class under the `<projectDir>/Test Listeners` directory) — a `testCaseContext` object is available only in a Test Listener code
2. ‘Script’ of a Test Suite — @SetupTestCase annotation is only available there

I think these 2 feature are totally unrelated beasts. They are not well designed to be used together.

If I were you, i will write all codes for setup/teardown aggregated in a TestListener. I personally never use `Script` of TestSuites.

---

<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:** [May 24, 2021, 12:47pm UTC](https://forum.katalon.com/t/tc-gettestcasestatus-passed-when-setuptestcase-fail/55076/3 "2021-05-24T12:47:07Z")

</div>

A failure occurred inside a method annotated with `@SetupTestCase` in a TestSuite — it is **not** a failure occurred inside a TestCase.

The TestCase itself might be invoked after the `@SetupTestCase` method. Or rather the TestCase might NOT be started at all when a failure occurred in the `@SetupTestCase` method.

Therefore `testCaseContext` in a TestListener, I think, will be ignorant of any failure occurred inside `@SetupTestCase` in TestSuite `Script`.

---

<div class="post-metadata">

**Author:** ![patryk.zywert](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/patryk.zywert/32/16103_2.png) [@patryk.zywert](https://forum.katalon.com/u/patryk.zywert)\
**Post date:** [May 24, 2021, 1:05pm UTC](https://forum.katalon.com/t/tc-gettestcasestatus-passed-when-setuptestcase-fail/55076/4 "2021-05-24T13:05:48Z")

</div>

Ok, the thing is that after @SetupTestCase fail, test listener is invoked anyway and there is some data about TC. That’s why i thought that i could use that to my advantage and throw there my code for handling exceptions. If there’s not status like IGNORED then i have to try diffrent approach.

Strange thing is that getTestCaseStatus returns PASSED, when TC never started. I thought that this might be a bug.

Anyway, thanks for your explanation.

---

<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:** [May 24, 2021, 1:08pm UTC](https://forum.katalon.com/t/tc-gettestcasestatus-passed-when-setuptestcase-fail/55076/5 "2021-05-24T13:08:28Z")

</div>

> [@patryk.zywert](#):
>
> Strange thing is that getTestCaseStatus returns PASSED, when TC never started. I thought that this might be a bug.

I didn’t know that. And I would not mind it, ever.
