# How to development Database for testing

**URL:** <https://www.ruby-forum.com/t/how-to-development-database-for-testing/193405>\
**Category:** Rails\
**Created:** [August 17, 2010, 6:35am UTC](https://www.ruby-forum.com/t/how-to-development-database-for-testing/193405 "2010-08-17T06:35:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [August 17, 2010, 6:35am UTC](https://www.ruby-forum.com/t/how-to-development-database-for-testing/193405/1 "2010-08-17T06:35:04Z")

</div>

Hi,

i want to use development database for my testing purpose.  
The problem is with, when test cases are run, it deletes the data before  
and after the test. but i dont want the data to be deleted.  
how to do this.

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [August 17, 2010, 7:04am UTC](https://www.ruby-forum.com/t/how-to-development-database-for-testing/193405/2 "2010-08-17T07:04:46Z")

</div>

Rajkumar S. wrote:

> Hi,
> 
> i want to use development database for my testing purpose.  
> The problem is with, when test cases are run, it deletes the data before  
> and after the test. but i dont want the data to be deleted.  
> how to do this.

Hi Rajkumar,  
You can duplicate your development database as testing database and  
specify the same in database.yml test environment. By doing this you  
will get the desired result without loosing data from development  
database.

Thanks,  
Anubhaw

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [August 17, 2010, 7:37am UTC](https://www.ruby-forum.com/t/how-to-development-database-for-testing/193405/3 "2010-08-17T07:37:45Z")

</div>

Anubhaw P. wrote:

> Rajkumar S. wrote:
> 
> > Hi,
> > 
> > i want to use development database for my testing purpose.  
> > The problem is with, when test cases are run, it deletes the data before  
> > and after the test. but i dont want the data to be deleted.  
> > how to do this.
> 
> Hi Rajkumar,  
> You can duplicate your development database as testing database and  
> specify the same in database.yml test environment. By doing this you  
> will get the desired result without loosing data from development  
> database.
> 
> Thanks,  
> Anubhaw

Hi,

But i don’t want to use seperate databases for testing and development .  
i need to use single database only.how to do this by using single  
database

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [August 17, 2010, 7:40am UTC](https://www.ruby-forum.com/t/how-to-development-database-for-testing/193405/4 "2010-08-17T07:40:20Z")

</div>

Rajkumar S. wrote:

> Hi,
> 
> i want to use development database for my testing purpose.

No you don’t. The point of a test database is to have something that  
your tests can run against without messing with your dev data.

> The problem is with, when test cases are run, it deletes the data before  
> and after the test. but i dont want the data to be deleted.

Yes you do. Tests must start from a known state, or they will not be  
reliable.

> how to do this.

Don’t. It’s a terrible, horrible, dangerous idea. Don’t even consider  
it.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

Sent from my iPhone

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [August 17, 2010, 8:54am UTC](https://www.ruby-forum.com/t/how-to-development-database-for-testing/193405/5 "2010-08-17T08:54:47Z")

</div>

Marnen Laibow-Koser wrote:

hi,  
May be but i need it to use single development database for both  
enviroments

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [August 17, 2010, 2:12pm UTC](https://www.ruby-forum.com/t/how-to-development-database-for-testing/193405/6 "2010-08-17T14:12:19Z")

</div>

stephenallred wrote:

> On Aug 17, 7:54ï¿½am, Rajkumar S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > May be but i need it to use single development database for both  
> > enviroments
> 
> Why?

Why indeed? That’s a BAD, DANGEROUS practice.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

Sent from my iPhone

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [August 17, 2010, 1:56pm UTC](https://www.ruby-forum.com/t/how-to-development-database-for-testing/193405/7 "2010-08-17T13:56:21Z")

</div>

On Aug 17, 7:54 am, Rajkumar S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> May be but i need it to use single development database for both  
> enviroments

Why?

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [August 17, 2010, 3:51pm UTC](https://www.ruby-forum.com/t/how-to-development-database-for-testing/193405/8 "2010-08-17T15:51:13Z")

</div>

Rajkumar S. wrote:

> Marnen Laibow-Koser wrote:
> 
> hi,  
> May be but i need it to use single development database for both  
> enviroments

Rails makes the right things to do very easy, and if you stray outside  
that, well you made a conscious decision to go that route, and bear the  
consequences.

You _are_ using automated testing aren’t you?

You _are_ keeping your tests up to date with the code and data changes  
you make in your development database on an ongoing basis?

You really need to look into some automated testing tools available for  
Rails to do this with any kind of replicability and efficiency.

If you absolutely, positively, against-all-reason-and-recommendation  
have to use the same database for dev and test, I would still not do  
exactly that.

I’d suggest you use sqlite for your development database, and copy your  
development.sqlite3 file to test.sqlite3 before running your tests, each  
and every time.

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [August 17, 2010, 6:45pm UTC](https://www.ruby-forum.com/t/how-to-development-database-for-testing/193405/9 "2010-08-17T18:45:04Z")

</div>

Take a look at some Rails testing resources -

> **[Testing Rails Applications — Ruby on Rails Guides](https://guides.rubyonrails.org/testing.html)**
>
> Testing Rails ApplicationsThis guide covers built-in mechanisms in Rails for testing your application.After reading this guide, you will know: Rails testing terminology. How to write unit, functional, integration, and system tests for your...

- take a look at the fixtures part.

I can’t think of a reason not to have a separate testing database or  
to try and run tests on the dev db, unless you are trying to re-invent  
the wheel and make your own test suite. I think quite a few of us have  
had the experience of trying to build something, like unit tests, that  
have in place several standard solutions already.
