EdPrescott
12 years agoNew Contributor
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?"
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")