Forum Discussion

hazem_borham's avatar
hazem_borham
Occasional Contributor
17 years ago

TestSuite does not execute a cloned testcase

I'm using the setup script section in my Test Suite to clone a test case, however, when I execute the testsuite it only runs the previously existing testcase.

Example.

Before running:

TestSuite 1
>> TestCase 1

After running:

TestSuite 1
>> TestCase 1 - OK
>> TestCase 2 (Is created but not run)

11 Replies

  • jkester's avatar
    jkester
    Occasional Contributor
    I found a trick here.
    You need to find the Junit ReportCollector. You can use an existing testcase and call all testrunlisteners.
    Then you look for any with JUnit.
    Then you clone your testcase, and finally, you add the existing reportcollector to listeners of the testcase.
    Now your junit report will also show the cloned test cases.

    Some example code I just tried out on 4.5:

    (1..5).each {
    //log.info it
    def templateTc = testRunner.testCase.testSuite.testCases["tc1"]
    def listenerList = testRunner.testCase.getTestRunListeners();
    def junitReportCollector = listenerList.find {
    it.class.name =~ 'JUnit'
    }
    log.info "JunitReportCollector = $junitReportCollector"
    def newName = "newtc$it"
    def tc = testRunner.testCase.testSuite.cloneTestCase(templateTc,newName)
    if (junitReportCollector != null) {
    tc.addTestRunListener(junitReportCollector);
    }
    log.info "Executing new testcase ${tc.name}"
    sleep(2000)
    def runner = tc.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)
    testRunner.testCase.testSuite.removeTestCase(tc);
    }