Setup/Teardown per test case

Best practices, code snippets for common functionality, examples, and guidelines.
armstronghm24
Posts: 42
Joined: Tue Dec 20, 2016 10:16 pm

Setup/Teardown per test case

Post by armstronghm24 » Tue Oct 30, 2018 7:51 pm

Hi,

I would like to perform a setup/teardown in a test case where the setup runs at the beginning, a number of the same test cases are run and then the teardown is run at the end. This works when the setup/teardown is at the test suite level, but it doesn't work correctly at the test case level. Why even provide the option of setup/teardown at the test case level if it repeats itself at each iteration of the test case anyway? Hopefully someone understands what I am getting at. Otherwise I can explain in further detail.

Vega
Posts: 222
Joined: Tue Jan 17, 2023 7:50 pm

Re: Setup/Teardown per test case

Post by Vega » Tue Oct 30, 2018 8:04 pm

What does your current test suite structure look like? Have you tried using smart folders within your test case(s)? It sounds like you are using either data binding or the iteration counter on your test case. Perhaps making a smart folder within the test case container and then applying the data binding / iteration counter to the smart folder could work for you. Perhaps something like this:

[TestCase]
--[Setup]
----[Smart Folder] *contains data binding / iteration counter
------[test modules] (these modules would be iterated over)
--[Teardown]

If this is not quite what you are looking for, it would be helpful if you are able to provide a screenshot of your test suite or at least an example.

armstronghm24
Posts: 42
Joined: Tue Dec 20, 2016 10:16 pm

Re: Setup/Teardown per test case

Post by armstronghm24 » Fri Nov 09, 2018 5:19 pm

I could use smart folders, but I would rather not as it is less organized from my perspective. I want something like this:
Test Suite
Test Suite Setup
- Testcase1
- Setup
- test case modules test case 1 (multiple iterations)
- Testcase2
- Setup
- Test case modules test case 2 (multiple iterations)

What is the purpose of the setup if it runs every time during a test case? Why not just make it a test case module? I want the setup to run once and then run through the test case modules multiple times in a test case.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Setup/Teardown per test case

Post by odklizec » Mon Nov 12, 2018 9:38 am

Hi,

In my opinion, the Setup/Teardown implementation, as it is now, is perfectly logical. But of course, it may not suit everybody ;) The thing is, that both Setup and Teardown are a part of iteration! In other words, the iteration starts once the test reaches the test case/smart folder, containing a data connector. Once the test enters the test case/smart folder, it goes into iteration 1 and so its setup/teardown section. Vega provided you with a perfectly working solution of the problem and it's exactly what I would do in case like yours. This is exactly what smart folders are for ;) If you don't like the current implementation of Setup/Teardown, you can always suggest a change via Ranorex User Voice platform, available here:
https://uservoice.ranorex.com/forums/15 ... ve-ranorex
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

armstronghm24
Posts: 42
Joined: Tue Dec 20, 2016 10:16 pm

Re: Setup/Teardown per test case

Post by armstronghm24 » Tue Nov 13, 2018 10:11 pm

I get your point. Thanks for the assistance.

spektr
Posts: 26
Joined: Thu Oct 22, 2020 11:53 am

Re: Setup/Teardown per test case

Post by spektr » Fri May 27, 2022 9:14 am

Hi, I will borrow this topic if I may :)

In my cas (picture) why teardown section is only triggered once - for the first test case. Why it doesn't trigger at the end of any of 4 test cases? Am I missing something?

Thanks
2022-05-27 10_12_59-nikolaj - Remote Desktop Connection.png
You do not have the required permissions to view the files attached to this post.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Setup/Teardown per test case

Post by odklizec » Fri May 27, 2022 9:32 am

Hi,

The Teardown section from your screenshot is at TestSuite level, which means it will be performed after all test cases are finished!

If you want a Teardown section to be performed at the end of each test, you must add Teardown section to each test case. Just right click the TestCase and from the context menu select "Add Teardown".
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

spektr
Posts: 26
Joined: Thu Oct 22, 2020 11:53 am

Re: Setup/Teardown per test case

Post by spektr » Fri May 27, 2022 9:41 am

hi :)

That was my previous solution, but i wanted to have this teardown section at one place.So now, If i run only the first test case it looks like the teardown is triggered since the browser gets closed at the end of test. So I assume that would be the case for the rest test cases too...

It looks like I was wrong. :) I was thinking how to do it, without copying the teardown section for each test case and bind parameters and variables and so on..

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Setup/Teardown per test case

Post by odklizec » Fri May 27, 2022 9:51 am

How exactly do you run your tests? The Test Suite Teardown should run always if the Test Suite is finished. Of course, if you, for example, run only a selected test case (via command line) and not the whole test suite, the Test Suite Teardown is not triggered ;) The solution is to use Run Configurations, where you can define which test cases should be included and then start the whole test suite with particular run configuration (instead of calling specific test case).
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

spektr
Posts: 26
Joined: Thu Oct 22, 2020 11:53 am

Re: Setup/Teardown per test case

Post by spektr » Fri May 27, 2022 10:18 am

Yes, maybe i will include run configuration again. I mean, so far i was using run configurations. But the test scenario became complex, so i open up a separate test suite, whereas I compose this complex test scenarion within test case.
I had an idea, to compose a test scenario in test case, so I would run it and it would represent the whole scenarion. Then I noticed that teardown region is always the same, so I was trying to avoid it :)
Maybe the simpliest way is to use run configurations again. :)

spektr
Posts: 26
Joined: Thu Oct 22, 2020 11:53 am

Re: Setup/Teardown per test case

Post by spektr » Fri May 27, 2022 1:30 pm

Odklizec, one more question If I may? Is there a way to use a validation like IF-ELSE option? Many times I am using validation to check wheter some item is present or not. Usually i do this no the start, but I don't have any options like IF-THEN to continue or to skip some test case if validation failed.

Thanks

spektr
Posts: 26
Joined: Thu Oct 22, 2020 11:53 am

Re: Setup/Teardown per test case

Post by spektr » Thu Jun 02, 2022 11:36 am

I have one more question, regarding my situation.

If I run my testcase through commandline, sending of email doesn't get triggered and i can't figure it out why. If I ran the test through ranorex, everything is fine.

For the main testsuite, works within command line. But for newly added testsuite, it doesn't...

Example:
image001.png
You do not have the required permissions to view the files attached to this post.

spektr
Posts: 26
Joined: Thu Oct 22, 2020 11:53 am

Re: Setup/Teardown per test case

Post by spektr » Thu Jun 02, 2022 2:53 pm

Solution is to set a run configuration with the same steps, then teardown si triggered.

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Setup/Teardown per test case

Post by Fergal » Thu Jun 02, 2022 5:24 pm

spektr wrote:
Fri May 27, 2022 1:30 pm
...I don't have any options like IF-THEN to continue or to skip some test case if validation failed...
A convenient way to achieve this could be by using error behavior. For example, you could have a few TCs in a smart folder, and set the error behavior of the TC to continue with parent.

Example:

Smart Folder 1
- TC1
- TC2
- TC3

Smart Folder 2
- TC4

If the error behavior of TC1 is set to Continue with Parent, then if TC1 fails, TC2 and TC3 will NOT be run.

More on Error Behavior in the Configure Error Behavior section here.