Automatic test data generation

We’ve all being there, we’ve all had this on a project once or maybe even more times. The assignment is to build an application but there is no data for you to work with. There could be any number of reasons this could be the case - to name a few, the web-service that should be connected is not done in time, the database migration is postponed. Then someone has to create database scripts with test data, or implement a test web-services. This is all a waste of time.

But lucky for you now there is a solution.

I've created an little framework that is easy to setup and will create test data automatically. So how does it work, simple, its entry point is a method interceptor that you can wrap around anything you want, there doesn't even have to be an implementation. So that DAO you want to use, but the database is still empty, just let our framework step into place and all the methods return the data that you want.

It is set up in a way that you don't need to configure a lot to get data, otherwise it will defeat it's purpose. The framework consists of generators. These generators can generate data for specific classes - for instance there is a FloatingPointGenerator that will generate floating point numbers randomly. The framework will try to figure out what kind of objects need to be returned, instantiate these objects and than generate data for all its properties.

Sometimes randomly created Strings or Numbers just won't work because it must be valid data. That's why you can override the defaults. For a specific field you can use an alternative generator. If for instance your domain model object has a postal code property you can set it up to use a the RegularExpressionInstanceGenerator. This generator can be used to generate Strings that match the regular expression that it was configured with.

If this article has raised your curiosity take a look at the sourceforge site for more information.

Comments (2)

  1. Ron Thijssen - Reply

    February 29, 2008 at 9:16 am

    This looks like a really interesting framework. Respect for sharing this little framework with us! I’m going to give it a try this weekend. Although, I still have some doubts about the feasibility.

    Cheers, Ron

  2. Erik Jan de Wit - Reply

    February 29, 2008 at 10:18 am

    Be sure to check out the example web application, default it works with the framework without configuration but when you add -Dbeesting.beangenerator.config.file=jag-example-generators.xml

    Then you can see the full potential of it.

Add a Comment