Forum Discussion

SiKing's avatar
SiKing
Community Expert
12 years ago

[Resolved] running testCase from testSuite teardown

I have a somewhat complicated test - testing for a race condition - so I have several testcase in a testsuite all run in parallel. The last testcase - one that verifies all the results - in the suite needs to be run only after all the other testcases are done.

I have achieved this by having my last verification case disabled, and I run it from the testsuite teardown script with:
testSuite.getTestCaseByName("verification").run((com.eviware.soapui.support.types.StringToObjectMap)context, true)

What does the second (boolean) parameter do?

If I boil down my verification testcase again to the bare minimum (for the purposes of this discussion) I have just a Groovy script:

try {
assert false : "failed assert"
} catch(Exception) {
testRunner.fail("failed testrunner")
}


When I run this setup from the GUI, the testcase fails (turn red), however the testsuite passes (stays green). How do I get the testsuite to "fail"?

When I run this setup from the command line testrunner, everything passes and I do not see either of the above messages. How do I get the testsuite to "fail"? Where should these two message be logged?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    > So does this mean there is a defect, or user error?

    Error on my part - I didn't do the monitoring setup correctly. Sorry for not getting it right immediately, but you're trying to do something rather unusual.

    Actually, it complains that the context variable context["#TestSuiteRunner#"] is null, not the testContext property. Odd, because it's found in my installation. What SoapUI version are you running?

    > Also, I am still unclear on how all this is suppose to be chained together. I need to end up with running one test case (retrieve and set up some data), followed by several test cases in parallel, followed by one test case (verification).

    Exactly. This worked for me.

    Regards,
    Manne
  • SiKing's avatar
    SiKing
    Community Expert
    SmartBear Support wrote:
    Actually, it complains that the context variable context["#TestSuiteRunner#"] is null, not the testrunner. Odd, because it's found in my installation. What SoapUI version are you running?

    4.6.0 Pro, 64bit, on Win7
  • SiKing's avatar
    SiKing
    Community Expert
    SmartBear Support wrote:
    ... but you're trying to do something rather unusual.

    If you search through my previous posts here and through your jira, you will find that specialize in unusual.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    SiKing wrote:
    SmartBear Support wrote:
    ... but you're trying to do something rather unusual.

    If you search through my previous posts here and through your jira, you will find that specialize in unusual.


    Hah, ain't that the truth

    I'm having problems reproducing the exception here. Manne's script is working fine out of the box for me. Please confirm that you're trying to run the TestSuite, because it breaks for me when I try to run the TestCases individually.

    Regards,
    Arian
    SmartBear Sweden
  • SiKing's avatar
    SiKing
    Community Expert
    Still no good.
    As I mentioned I heed to run one test step, followed by several steps in parallel, followed by one test step. What I am seeing is that _everything_ runs in parallel. In fact my last step - the verification - often completes before any of the other ones. I see the warning: "monitor not found in completion check".
    I can mail you the project along with all the .log files - please PM me or email an address where I can send it; I cannot post this on a public forum.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    So as I replied you on the mail, sharing this in the forum also. You have to setup the monitor on the test suite setup since, if you run the test cases parallelly there is no gurantee which test case will run first. So, can't have the monitor setup code inside the test case. There was some minor problem with the code snippet that was shared in earlier reply, probably that is why you were unable to use it on the setup. Try the following one

    def monitor = new com.eviware.soapui.monitor.TestMonitor()

    testSuite.testCases.each {
    testCase = it.value
    if ( testCase.label != "verify and cleanup") {
    log.info("monitoring $testCase.label")
    monitor.monitorTestCase(testCase)
    }
    }

    runner.runContext.testMonitor = monitor


    And on your "verify and cleanup" test step have the wait for completion check as usual before verification step. Hope this works.

    Regards,
    Shadid
    SmartBear Sweden
  • SiKing's avatar
    SiKing
    Community Expert
    This gets me half-way there ... but I got the rest of it figured out from here.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,
    Good to hear that you got it working and thanks for the blog post. This will definitely help others as well.

    Best Regards,
    Prakash
    SmartBear Sweden