views:

619

answers:

4

Hi,

I need to insert dummy data on test environtment so that I can run unit test on it but I don't know how to declare it on BootStrap (just for testing, not for all environtment)

can you help me ? thank you in advance

+2  A: 

Creating "dummy data" is a part of the Test Fixture. You can use the Fixtures Plugin for this.

+2  A: 

as noted, you can use the test fixture. you can also put code in bootstrap (http://www.transentia.com.au/flatpress/2009/08/09/pimped-out-grails-bootstraps/). if you are using junit 4, you might be able to use @BeforeClass. also, there is http://grails.org/plugin/build-test-data that may be of interest.

if you really mean unit test (as opposed to integration test), take a look at http://grails.org/Testing+Plugin (these run fast).

Ray Tayek
thanks this is what i need, put the dummy data on bootstrap.
nightingale2k1
The first link is dead :(
Tom
this one just worked: http://wordpress.transentia.com.au/wordpress/2009/08/09/pimped-out-grails-bootstraps/
Ray Tayek
also: http://blog.burningice.pl/2009/05/11/pimp-my-grails-bootstrap/
Ray Tayek
i just use: switch (GrailsUtil.environment) { case "development": ... break }
Ray Tayek
+2  A: 

BootStrap.groovy is the right place for this as the other commenters have suggested. Though I'd suggest using the build-test-data plugin to create your dummy data (disclaimer: I wrote it :).

It makes it easy to create a bunch of data quickly and it automatically fills in the required fields that you don't specify. This makes your bootstrap data MUCH easier to maintain compared to a bunch of fixtures that need to be tweaked every time you modify your domain classes.

Ted Naleid
A: 

If you want to guarantee that the dummy test data will be removed when the test completes, the best way to achieve this is by loading the test data in the setUp() method. This ensures that the data is loaded within the same transaction as the test itself, so it will be rolled back (removed) when the test completes.

I use DbUnit to load the data from an XML file in the setUp() method, because I find it's easier to read the test code and the test data when the two aren't mixed up in the same .groovy file.

Don