使用模拟MongoDB服务器进行单元测试 [英] Use mock MongoDB server for unit test

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

问题描述

我必须使用MongoDB存储为Python代码实现鼻子测试.有没有允许我初始化模拟内存MongoDB服务器的python库?

I have to implement nosetests for Python code using a MongoDB store. Is there any python library which permits me initializing a mock in-memory MongoDB server?

我正在使用持续集成.因此,我希望我的测试独立于任何运行MongoDB的服务器. 有没有一种方法可以在内存中模拟mongoDM Server,以独立于连接到Mongo Server来测试代码?

I am using continuous integration. So, I want my tests to be independent of any MongoDB running server. Is there a way to mock mongoDM Server in memory to test the code independently of connecting to a Mongo server?

提前谢谢!

推荐答案

您可以尝试: https://github. com/vmalloc/mongomock ,旨在成为一个小型库,用于模拟pymongo集合对象以进行测试.

You could try: https://github.com/vmalloc/mongomock, which aims to be a small library for mocking pymongo collection objects for testing purposes.

但是,与确保某些模拟库功能完整相比,我不确定仅运行mongodb的成本是否会过高.

However, I'm not sure that the cost of just running mongodb would be prohibitive compared to ensuring some mocking library is feature complete.

这篇关于使用模拟MongoDB服务器进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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