Creating and extending test data builders
gw.api.databuilder.DataBuilder or classes that reside in the gw.api.databuilder.* package in a production environment. Guidewire provides GUnit as a development test facility only.As you run tests against code, you need to run these test in the context of a known set of data objects. This set of objects is generally known as a test fixture. You use Gosu entity builders to create the set of data objects to use in testing.
Guidewire provides a number of entity “builders” as utility classes to quickly and concisely create objects (entities) to use as test data. The PolicyCenter base configuration provides builders for the base entities (such as PolicyBuilder,
for example). However, if desired, you can extend the base DataBuilder class to create new or extended entities. You can commit any test data that you create using builders to the test database using the bundle.commit method.
For example, the following builder creates a new Person object with a FirstName property set to “Sean” and a LastName property set to “Daniels”. It also adds the new object to the default test bundle.
var myPerson = new PersonBuilder()
.withFirstName("Sean")
.withLastName("Daniels")
.create()
For readability, Guidewire recommends that you place each configuration method call on an indented separate line starting with the dot. This makes code completion easier. It also makes it simpler to alter a line or paste a new line into the middle of the chain or to comment out a line.
Gosu builders extend from the base class
gw.api.databuilder.DataBuilder.
To view a list of valid builder types in Guidewire PolicyCenter, use the Studio code
completion feature. Type gw.api.databuilder.
in the Gosu editor and Studio displays the list of available builders.
Package completion
As you create an entity builder, you must
either use the full package path, or add a uses statement at the beginning
of the test file. However, in general, Guidewire recommends that you
place the package path in a uses
statement at the beginning of the file.
uses gw.api.databuilder.AccountBuilder
@gw.testharness.ServerTest
class MyTest extends TestBase {
construct(testname : String) {
super(testname)
}
...
function testSomething() {
//perform some test
var account = new AccountBuilder().create()
}
...
}
Guidewire provides certain of the Builder classes in gw.api.builder.* and others in
gw.api.databuilder. Verify
the package path as you create new builders.
