Enables the easy creation of test data by automatic inspection of constraints. Any properties that are required have their constraints examined and a value is automatically provided for them.
Groovy Java


Build Status

The Build Test Data Grails Plugin

Note: Version 3.0.0 supports Grails 3.0.0 and higher, please continue to use 2.4.0 for Grails 2.4.x

Creating maintainable test data is hard. Often an entire object graph needs to be created to support the instantiation of a single domain object. This leads to either the cutting and pasting of that creation code, or relying on a canned set of objects that we've grown over time and maintained as the domain objects change. After a while, adding just one more Widget to that set of canned data ends up breaking tests just about every time.

There has to be a better solution, right?

Yep! Due to the power and the glory of Grails, we have a lot of metadata at our fingertips about those domain objects. We know what constraints we've placed on our objects, and which objects depend on other objects to live.

Using this additional information, we've created a grails plugin that makes it easy to just provide those values that you want to exercise under test and not worry about the rest of the object graph that you need to create just to instantiate your domain objects.

This plugin is focused on creating test data for integration testing. As of Grails 2.0.0, build-test-data also supports unit tests through annotations and mixins.

Once installed, all you have to do is call the new "build" method on your domain class and you'll be given a valid instance with all of the required constraints given values.

def a = Author.build()

In a unit test, you'll just use an annotation to let it know what domain class you'd like to build

import grails.buildtestdata.mixin.Build

class AuthorUnitTests {

    void testAuthorStuff() {
        def author = Author.build()


Plugin Objectives