Forum Discussion

Xarx123's avatar
Xarx123
Occasional Contributor
11 years ago

Returning values from TestCase

I'm trying to modularize my test cases, so I'm running a shared test case (as a procedure) that does something useful and returns a result value. As I need to pass-in non-string input properties, I have to run the test case from groovy:
def findLoopEndTC = testRunner.testCase.testSuite.testCases["TestCase - Find Loop End"]
assert findLoopEndTC != null, "Referred TC not found"

def runContext = new com.eviware.soapui.support.types.StringToObjectMap()
runContext.put("TestStepContext", context)
def runner = findLoopEndTC.run( runContext, false )
assert runner.status != com.eviware.soapui.model.testsuite.TestRunner.Status.FAILED : runner.reason

I've learned that the test case is run using the SINGLETON_AND_WAIT mode which ensures that the TestCase itself is run in a thread-safe way.
My question is how to return a value from the run test case in a thread-safe way?

I tried
runner.getRunContext().getProperty("Result")
, but it seems that the context properties are no longer there. So there seems to be only the "classical" way,
findLoopEndTC.getPropertyValue("Result")
, but this seems to be not thread-safe.
Are there other possibilities?

2 Replies

  • Xarx123's avatar
    Xarx123
    Occasional Contributor
    I've resoved passing of non-string parameters forth and back when calling another TestCase by passing in a map aimed for setting of return values:

    The caller:
    //call another TC
    def tc = testRunner.testCase.testSuite.testCases["TestCase Proc"]
    assert tc != null, "Referred TC not found"

    def tcContext = new com.eviware.soapui.support.types.StringToObjectMap()
    def returns = [:]
    tcContext.put("input", 345)
    tcContext.put("returns", returns)

    def runner = tc.run( tcContext, false )
    assert runner.status != com.eviware.soapui.model.testsuite.TestRunner.Status.FAILED : runner.reason

    context.setProperty("output", returns.get("output",null))

    com.eviware.soapui.support.UISupport.showInfoMessage(context.getProperty("output").toString())

    The callee:
    def input = context.getProperty("input");
    def returns = context.getProperty("returns");
    returns.put("output",input + 1);

    Unfortunately, this didn't help me with reuse of the TestCases in load tests, as the method tc.run() itself has fundamental thread-safety flaws, see the bug viewtopic.php?f=13&t=21961.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    See my reply to the other forum post.

    Kind regards,
    Manne
    SmartBear Support