# Functional testing - don't create schema each time

**URL:** <https://www.ruby-forum.com/t/functional-testing-dont-create-schema-each-time/161834>\
**Category:** Rails\
**Created:** [March 2, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/functional-testing-dont-create-schema-each-time/161834 "2009-03-02T23:23:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Obelix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e68b1a/32.png) [@Obelix](https://www.ruby-forum.com/u/Obelix)\
**Post date:** [March 2, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/functional-testing-dont-create-schema-each-time/161834/1 "2009-03-02T23:23:19Z")

</div>

Setting up the data for my rails server is non trivial, it includes  
schema creation, seeding the database with seed data, running indexing  
using ferret.

I want to write functional tests that use the seed data and indices.

However, each time I run the functional tests, the db schema gets  
dropped and re-created. Is there a way to preserve existing schema  
and not re-create it each time?

thanks

---

<div class="post-metadata">

**Author:** ![Obelix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e68b1a/32.png) [@Obelix](https://www.ruby-forum.com/u/Obelix)\
**Post date:** [March 3, 2009, 2:15am UTC](https://www.ruby-forum.com/t/functional-testing-dont-create-schema-each-time/161834/2 "2009-03-03T02:15:04Z")

</div>

Obelix wrote:

> Setting up the data for my rails server is non trivial, it includes  
> schema creation, seeding the database with seed data, running indexing  
> using ferret.
> 
> I want to write functional tests that use the seed data and indices.
> 
> However, each time I run the functional tests, the db schema gets  
> dropped and re-created. Is there a way to preserve existing schema  
> and not re-create it each time?

Then it wouldn’t be a test.

You need to test by running each step in the setup for the test for the  
subsequent step. Test seeding by asserting the DB is empty (or by  
emptying your  
fixtures out!), call the seed method, and assert the database is seeded.  
Test  
indexing by seeding the database, asserting ferret is unindexed, calling  
the  
indexer, and asserting ferret can find data. And so on.

Test isolation is very important, and ActiveRecord will fight  
you to preserve it. AR will think that you have simply neglected to tear  
down  
some database detail, and will diligently tear it down for you!

–  
Phlip  
[http://www.zeroplayer.com/](http://www.zeroplayer.com/)

---

<div class="post-metadata">

**Author:** ![Obelix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e68b1a/32.png) [@Obelix](https://www.ruby-forum.com/u/Obelix)\
**Post date:** [March 3, 2009, 3:48am UTC](https://www.ruby-forum.com/t/functional-testing-dont-create-schema-each-time/161834/3 "2009-03-03T03:48:48Z")

</div>

Thanks.

I guess we disagree on what I want to test :).

It was a simple solution of creating my own rake tasks, instead of  
using the pre-built rake tasks.
