How to run testcase in certain order?

Hi,
i have a folder in testcase which contains several testcases and i want to run them in certain order.
structure of my testcase is:

Test Cases
-Folder1
-testcase1_runner
-testcase2
-testcase3
-testcase4
-testcase5
-testcase_final

So what i want run testcase1_runner which will execute:
testcase_1
tescase_2
testcase_final
then
testcase_1
testcase_3
testcase_final
then
testcase_1
testcase_4
testcase_final

Is there a way to do it with a loop?

im trying with this:

//1- run testcase1
WebUI.callTestCase(findTestCase(‘Folder1/testcase1’), [:], FailureHandling.STOP_ON_FAILURE)

//2- execute testcase2
WebUI.callTestCase(findTestCase(‘Folder1/testcase2’), [:], FailureHandling.STOP_ON_FAILURE)

//3- execute testcase_final
WebUI.callTestCase(findTestCase(‘Folder1/testcase_final’), [:], FailureHandling.STOP_ON_FAILURE)

Thank you

You’re probably already taking the best approach. Here’s why…

A Test Case needs to be READABLE. It should be very clear, even to the casual reader, what it is trying to achieve.

Could you (or anyone) write a super intelligent procedure that computes “what is next” and stick it in a loop? Absolutely. But would it be readable?

Now think about the only constant in testing (or anything for that matter)… the requirements will change. Change, as we all know, is a constant.

When you come to modify your chosen structure and approach, which one do you think is the easiest to modify? What if the person making the change is not you?

The only other thing you might consider is to add the tests, in the order you wish them to execute, to a suite. But really, there’s nothing wrong with callTestCase() and a master test case.

Aside: There has been talk about ad hoc suite creation where a suite is created in memory (via code) and executed. I haven’t heard when that might appear but I live in hope. (hint hint @ThanhTo)

1 Like

If you get rid of your existing instance of Junit, and download JUnit 4.11 or greater in the build path, the following code will execute the test methods in the order of their names, sorted in ascending order:

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SampleTest {

@Test
public void testAcreate() {
    System.out.println("first");
}
@Test
public void testBupdate() {
    System.out.println("second");
}
@Test
public void testCdelete() {
    System.out.println("third");
}

@Lewis-H Can you please explain what JUnit has to do with Katalon Test Cases?