Sham Plugin

  • Tags : /
  • Latest : 0.3
  • Last Updated: 06 February 2013
  • Grails version : 1.3.7 > *
0 vote
Dependency :
compile ":sham:0.3"

Documentation Source Issues

Summary

A plugin using the sham data generation library to generate test / demo data when testing your app.

Installation

grails install-plugin sham

Description

This plugin allows easy generation of realistic test data for your application.

If you are currently using the build-test-data or fixtures plugins, you will be familiar with your data having the same values over and over again, maybe with an index number if you're lucky. This doesn't help you show your application to your customer, and it doesn't help you see how resilient your website layout is to differently sized content.

This is where the sham library and plugin can help.

Usage

Once you have installed the plugin, there is a sham bean available in your Grails application context or for dependency injection. Alternately, there is a static instance available by calling Sham.instance , and this may be more useful in your tests.

Example

If you have a fixture which previously had some hardcoded data set up:
build {
    myArticle(com.foo.Article) {
        title = 'Exciting headline here'
        teaser = 'Some really exciting text that should make someone click through to the underlying article'
        text = 'Full article copy here'
        author = 'Joe Bloggs'
    }
}

it could be made much more dynamic with the application of soms Sham data:

def sham = Sham.instance
build {
    myArticle(com.foo.Article) {
        title = sham.nextHeadline()
        teaser = sham.nextParagraph()
        text = sham.nextParagraphs() // produces random number of paragraphs between 1 and 8
        author = sham.nextPerson().name
    }
}

This will create an article with randomly generated news headline, body text, teaser and author name.

Full documentation coming soon! In the meantime, have a look at the fixtures in the demo app in the source, or check out what data generation is available in the library