Forum Discussion

EdPrescott's avatar
EdPrescott
New Contributor
11 years ago

How to share test cases between Projects?

We have implemented test logic we want to share across test cases (in the same project and in different projects). We share this logic between test cases in the same project by incorporating the logic into "helper" test cases. These "helper" test cases are disabled, and they are called by multiple, real test cases. This works fine to share test code between test cases in the same project.

But what is the best way to share test logic between projects? I wrote the Groovy script below to try this out. In this case, "Submit An Order" is a "helper" test case in another project. I can run the test case in the other project just fine, but when I try to push properties to the test case's invocation, it doesn't work, and when I try to read properties from the result of the invocation, no properties of the invocation are returned. I do see returned all of the default variables defined on the "helper" function, but the invocation of the "helper" function fills in the values of several properties, and those are not seen.

Do you know if it is possible to push properties to test case invocations in other projects (and receive properties from them)? Or, more generally, "What is the best way to share test code between test cases in different projects?"


// Get the root workspace object
def workspace = testRunner.getTestCase().getTestSuite().getProject().getWorkspace()

//Find helper, navigating by name.
def submitOrderHelper = workspace.getProjectByName("COP (Resale BVTs)").getTestSuiteByName("COP Helpers").getTestCaseByName("Submit An Order")

props = context.getProperties()
props << ["quantity":"2"]

// Run the testcase in the other project. The return type is WsdlTestCaseRunner (or some other TestCaseRunner)
submitOrderResult = submitOrderHelper.run(props,false)

testCaseProps = submitOrderResult.getProperties()["testCase"].getProperties()
log.info testCaseProps
log.info "Testcase props"

String[] keys = testCaseProps.keySet()
for (String key in keys)
{
propertiesStepProperty = testCaseProps.getAt(key)
log.info key + " = " + propertiesStepProperty
log.info key + " = " + propertiesStepProperty.getValue()
}

log.info "OrderID from test case props" + testCaseProps["OrderID"].getValue()
log.info "End testcase props"

def status = submitOrderResult.getProperties()["status"].toString()
log.info "Status:" + status
assert (status == "FINISHED")

3 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    You should be able to run a test case from a different project with the following Groovy script:

    //get test case from other project
    project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName(project_name)
    testSuite = project.getTestSuiteByName(suite_name);
    testCase = testSuite.getTestCaseByName(testcase_name);

    //set properties
    testRunner.testCase.setPropertyValue(property_name, property_value);
    testRunner.testCase.setPropertyValue(another_property_name, another_property_value);


    // run test case
    runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);


    Thanks,
    Michael Giller
    SmartBear Software
  • EdPrescott's avatar
    EdPrescott
    New Contributor
    Thank you, Michael, I appreciate it. Is there any way to use the resulting runner object to get property values set by the test case?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Double click on the Test Case. Then in the Test Case window you'll see a "Setup Script" tab. You can use that tab to instantiate the objects that you can then refer to at runtime.

    Thanks,
    Michael Giller
    SmartBear Software