Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unit testing with in-memory database [duplicate]

I have PostgreSQL database. It is used for unit testing.

  • I want to speed the tests up so I want to use some kind of in-memory databases (e.g. H2).
  • I want to dump the database (from PostgreSQL) and the import such a dump into in-memory database.

Do you have any suggestion concerning in-memory database choice? I want that database to be compatible with PostgreSQL.

like image 394
Lucas Smith Avatar asked Aug 01 '12 17:08

Lucas Smith


2 Answers

I'd simply create a database directory (called a cluster in PostgreSQL) in tmpfs (essentially a RAM-disk - /dev/shm is configured as such in most Linux distributions) and simply run postgres there on non-standard port, for example like this:

initdb -D /dev/shm/pgtest
postmaster -D /dev/shm/pgtest -p 11111
like image 115
Tometzky Avatar answered Oct 04 '22 20:10

Tometzky


I would recommend using HSQL with a spring combination. I was brought on to my current occupation to do this exact thing, and even though it is a headache, it can be done. And based on quick research, it appears hsql is compatible with PostgreSQL. Let me know if you have any other questions.

like image 33
nook Avatar answered Oct 04 '22 22:10

nook