Page 1 of 1

Setup/Teardown per test case

Posted: Tue Oct 30, 2018 7:51 pm
by armstronghm24
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.

Re: Setup/Teardown per test case

Posted: Tue Oct 30, 2018 8:04 pm
by Vega
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.

Re: Setup/Teardown per test case

Posted: Fri Nov 09, 2018 5:19 pm
by armstronghm24
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.

Re: Setup/Teardown per test case

Posted: Mon Nov 12, 2018 9:38 am
by odklizec
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

Re: Setup/Teardown per test case

Posted: Tue Nov 13, 2018 10:11 pm
by armstronghm24
I get your point. Thanks for the assistance.

Re: Setup/Teardown per test case

Posted: Fri May 27, 2022 9:14 am
by spektr
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

Re: Setup/Teardown per test case

Posted: Fri May 27, 2022 9:32 am
by odklizec
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".

Re: Setup/Teardown per test case

Posted: Fri May 27, 2022 9:41 am
by spektr
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..

Re: Setup/Teardown per test case

Posted: Fri May 27, 2022 9:51 am
by odklizec
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).

Re: Setup/Teardown per test case

Posted: Fri May 27, 2022 10:18 am
by spektr
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. :)

Re: Setup/Teardown per test case

Posted: Fri May 27, 2022 1:30 pm
by spektr
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

Re: Setup/Teardown per test case

Posted: Thu Jun 02, 2022 11:36 am
by spektr
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

Re: Setup/Teardown per test case

Posted: Thu Jun 02, 2022 2:53 pm
by spektr
Solution is to set a run configuration with the same steps, then teardown si triggered.

Re: Setup/Teardown per test case

Posted: Thu Jun 02, 2022 5:24 pm
by Fergal
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.