Setup new data in the test database _after_ unit test runs

All,

I want to run automated unit tests as part of my build. I am building
to my test environment. Upon successful completion of all of my unit
tests, I would then like to load some data (using a fixture, I imagine)
into my test database that will act as fresh “system test” data for my
users to play with.

What is the best way to “load the standard system test/user acceptance
data” after I’ve successfully run through all of my automated tests?

Thanks,
Wes

Wes G. wrote:

All,

I want to run automated unit tests as part of my build. I am building
to my test environment. Upon successful completion of all of my unit
tests, I would then like to load some data (using a fixture, I imagine)
into my test database that will act as fresh “system test” data for my
users to play with.

What is the best way to “load the standard system test/user acceptance
data” after I’ve successfully run through all of my automated tests?

Thanks,
Wes

Or should I just have a separate Rails environment for “system test” (as
opposed to unit test) and manage that data separately? Even if I did
that, I would still want an easy way to load/delete the system test data
set easily.

WG

On Tue, Jul 11, 2006, Wes G. wrote:

All,

I want to run automated unit tests as part of my build. I am building
to my test environment. Upon successful completion of all of my unit
tests, I would then like to load some data (using a fixture, I imagine)
into my test database that will act as fresh “system test” data for my
users to play with.

What is the best way to “load the standard system test/user acceptance
data” after I’ve successfully run through all of my automated tests?

There is a rake task for this purpose. rake db:fixtures:load

You could either run that after your tests are done (and you do a purge)
or, alternately, structure your tests/fixtures so that when they finish
running, the data is still valid and interesting. For instance, you
might do destructive tests before constructive tests, so that once the
tests are finished, the test objects you created still exist.

Ben

Thanks, Ben, I figured it was a no-brainer.

On Tue, Jul 11, 2006, Wes G. wrote:

Is there a way to specify the order in which the data is loaded so that
FK constraints aren’t broken?

I don’t know for sure. My gut tells me no, since I believe it just
loads everything into hashes and hash order is unpredictable. Other
people probably know better than I do; I primarily develop with MySQL so
it’s not a problem for me :wink:

Ben

Wes G. wrote:

Is there a way to specify the order in which the data is loaded so that
FK constraints aren’t broken?

Because I wanted to use the existing data in my DB for my test data, I
easily dumped it to YAML using the following:

File.open(‘filename’, “w”) { |f| YAML.dump(ModelObject.find(:all), f)}

Is there a way to specify the order in which the data is loaded so that
FK constraints aren’t broken?

Wes G. wrote:

Wes G. wrote:

Is there a way to specify the order in which the data is loaded so that
FK constraints aren’t broken?

Because I wanted to use the existing data in my DB for my test data, I
easily dumped it to YAML using the following:

File.open(‘filename’, “w”) { |f| YAML.dump(ModelObject.find(:all), f)}

It appears that just calling db:fixtures:load will load the fixture
files in alphanumeric order, so I may just prefix the files in such a
way that they will load in the correct order.

Wes

On 7/10/06, Wes G. [email protected] wrote:

It appears that just calling db:fixtures:load will load the fixture
files in alphanumeric order, so I may just prefix the files in such a
way that they will load in the correct order.

There is usually a command to tell your db to ignore constraints - I
know you can switch the fk constraints on and off with mysql. So one
solution I’ve seen is a simple script that turns of fk constraints,
does all the data loading, then turns constraints back on.