Creating multiple test objects from a template object
In some situations, a test may require a set of objects that have nearly identical settings. For example, there could be a test that requires a set of activities that have the same type and priority.
You can create multiple test objects with the same values using a template object. A
template object is an object created from a test data builder class whose
create method is never called. Instead, multiple objects are declared and
created from it.
To use a template object:
- Declare the template object.
- On the template object, set the values that need to be identical on each of the test
objects.
- Do not execute the
createmethod on the template object.
- Do not execute the
- Create the test objects from the template object.
- Execute the
createmethod on the test objects only.
- Execute the
The following code is an example of creating multiple activities from a template object. The type and priority fields are set in the template object. Therefore, both activities have the same type and priority. However, each activity has a distinct subject.
gw.transaction.Transaction.runWithNewBundle( \ bundleObj -> {
var templateActivityBuilder = new gw.api.databuilder.ActivityBuilder()
.withType(ActivityType.TC_GENERAL)
.withPriority(Priority.TC_HIGH)
var activity1 = templateActivityBuilder
.withSubject("Test activity 1")
.create(bundleObj)
var activity2 = templateActivityBuilder
.withSubject("Test activity 2")
.create(bundleObj)
} , "su" )
