Forum Discussion

Progster's avatar
Progster
Occasional Contributor
12 years ago

Organizing TestSuite

Hi,

In a testsuite, i have several testcases that i want to organize sequentialy. Can anyone helpme please?

Example:

1- TestCase A
10 - TestCase E
6 - TestCase B
4 - TestCase C
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    Systematically, this will be extremely difficult. The only way I could possibly see this happening would be with a groovy script that gets all of the names, builds an arraylist, sorts the array list and then moves the TestSteps based on the order they are in with the ArrayList. The problem, you can't just move a Test Case to a specific spot. I will play with some code and see if I can get this to be accomplished.


    I would suggest just manually reordering though.


    So after some testing I have found that this might be even more difficult than I thought, within SoapUI at least. Since the getTest*List() is importing the tests themselves, it won't sort by name. So it will have to build an array list of names, sort those, grab them by the name and then organize them where they are supposed to go.


    And here you go. It uses sorting based on Alphanumeric style of the name; Numbers first, Capital Letters and then Lowercase letters. However, it will recognize things like 10 as lower than 9. If you want to go with a purely numeric style just have it use the number as the index and skip a lot of this stuff.

    ArrayList<String> suiteList = new ArrayList<String>();
    for (testsuite in testRunner.testCase.testSuite.project.workspace.getProjectByName("ProjectName").getTestSuiteList()) {
    suiteList.add(testsuite.getName());
    }
    suiteList.sort();
    int i = 0;
    for (suite in suiteList) {
    def curSuite = testRunner.testCase.testSuite.project.workspace.getProjectByName("ProjectName").getTestSuiteByName(suite);
    curIndex = testRunner.testCase.testSuite.project.workspace.getProjectByName("ProjectName").getIndexOfTestSuite(curSuite);
    testRunner.testCase.testSuite.project.workspace.getProjectByName("ProjectName").moveTestSuite(curIndex,i-curIndex);
    i++;
    }


    I made it to where it's more versatile and can work with any project you wanted, or all if you wanted to convert it. Also mine is ordering test suites. I will make some adjustments to handle test cases really quick.
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    And for ordering TestCases:

    ArrayList<String> suiteList = new ArrayList<String>();
    for (testsuite in testRunner.testCase.testSuite.project.workspace.getProjectByName("projectName").getTestSuiteByName("TestSuiteName").getTestCaseList()) {
    suiteList.add(testsuite.getName());
    }
    suiteList.sort();
    int i = 0;
    for (suite in suiteList) {
    def curSuite = testRunner.testCase.testSuite.project.workspace.getProjectByName("projectName").getTestSuiteByName("TestSuiteName").getTestCaseByName(suite);
    curIndex = testRunner.testCase.testSuite.project.workspace.getProjectByName("projectName").getTestSuiteByName("TestSuiteName").getIndexOfTestCase(curSuite);
    log.info curIndex;
    testRunner.testCase.testSuite.project.workspace.getProjectByName("projectName").getTestSuiteByName("TestSuiteName").moveTestCase(curIndex,i-curIndex);
    i++;
    }
  • Progster's avatar
    Progster
    Occasional Contributor
    Sorry, i'm new with soapui. Where can i use this code?
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    It's okay. That would be a groovy test step, anywhere in SoapUI. Just rename the projectName and TestSuiteName portions based on what they should be. Run the test step and it will reorganize the TestSuite that you directed it to.