使用内存数据库进行单元测试 [英] unit testing with in-memory database

查看:186
本文介绍了使用内存数据库进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有PostgreSQL数据库。用于单元测试。

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


  • 我想加快测试速度,所以我想使用某种内存数据库(例如H2)。

  • 我要转储数据库(从PostgreSQL),并将这样的转储导入内存数据库。

您对内存数据库选择有何建议?我希望该数据库与PostgreSQL兼容。

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

推荐答案

我只是创建一个数据库目录(在PostgreSQL中称为集群)在tmpfs中(基本上是一个RAM磁盘- / dev / shm 在大多数Linux发行版中都是这样配置的),并且只需在非标准端口上运行postgres,例如这样:

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

这篇关于使用内存数据库进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆