Aaron edited this page Jan 7, 2018 · 12 revisions

The Build Test Data Grails Plugin

NOTE: This documentation is for build-test-data 2.x and 3.0 versions. If you are using Grails 3.3 or later, please see the documentation at http://longwa.github.io/build-test-data/index

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()

Plugin Objectives

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.