与MongoDB进行集成测试? [英] Integration tests with MongoDB?
问题描述
我需要使用Java在Mongo数据库上进行几次集成测试,我一直在寻找一种类似DbUnit的解决方案(DbUnit用于Hibernate),该解决方案可以用自定义数据填充我的数据库,并在每次运行后重置状态.
I need to do several integration tests on a Mongo database using Java, and I was looking for a DbUnit-like solution (DbUnit is for Hibernate) that can populate my database with custom data, and reset the state after each run.
有什么提示吗?
谢谢
推荐答案
首先,我不知道有任何直接等效于Mongo的DBUnit. Mongo仍然是一种新产品,因此您可能需要为其中的某些东西自己动手".
To start off, I don't know of any direct equivalent to DBUnit for Mongo. Mongo is still a new product, so you'll probably have to "roll your own" for some of this stuff.
但是,Mongo的一些功能应该可以简化此操作:
However, there are several features of Mongo that should make this easy:
- 它以最小的权限运行
- 它可以简单地运行"准备好的文件
- 它实际上没有架构(索引除外)
- 它可以处理JSON数据
根据您的数据集,有很多方法可以做到这一点.但是这里有基本的工具.
Based on your dataset there are lots of ways to do this. But the basic tools are there.
- 您应该能够从测试中启动专门针对您的测试的版本.
- 您应该能够从JSON文件导入状态"数据.
- 您应该能够从JS文件(从头开始)应用任何服务器端功能.
因此,整个过程应该非常简单.尽管您将不得不编写很多粘合代码.
So the whole thing should be pretty straightforward. Though you will have to write much of the glue code.
这篇关于与MongoDB进行集成测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!