当前位置:网站首页>Unit testing with mongodb
Unit testing with mongodb
2022-07-01 05:05:00 【Superior virtue and weak water】
problem :
My database of choice is MongoDB. The database I chose is MongoDB.I'm writing a data-layer API to abstract implementation details from client applications - that is, I'm essentially providing a single public interface (an object which acts as an IDL). I am writing a data layer API To abstract the implementation details from the client application - in other words , I actually provide a separate public interface ( One acts as IDL The object of ).
I'm testing my logic as I go in a TDD manner. I'm taking TDD To test my logic .Before each unit test, an @Before method is called to create a database singleton, after which, when the test completes, an @After method is called to drop the database. Before each unit test , call @Before Method to create a database singleton , after , When the test is complete , call @After Method to delete the database .This helps to promote independence among unit tests. This helps to improve the independence between unit tests .
Nearly all unit tests, ie performing a contextual query , require some kind of insertion logic to occur before hand. Almost all unit tests , namely Execute context query , All need some kind of insertion logic in advance .My public interface provides an insert method - yet, it seems incorrect to use this method as precursor logic to each unit test. My public interface provides an insertion method - However , It seems incorrect to use this method as the precursor logic of each unit test .
Really I need some kind of mocking mechanism, yet, I haven't had much experience with mocking frameworks, and it seems that Google returns nothing re a mocking framework one might use with MongoDB. I really need some sort of simulation mechanism , however , I don't have much experience with simulation frameworks , and Google It doesn't seem to return any possibility with MongoDB Simulation framework used together .
What do others do in these situations? What others have done in these situations ?That is, how do people unit test code that interacts with a database? in other words , How do people unit test code that interacts with databases ?
Also, my public interface connects to a database defined in a external configuration file - it seems incorrect to use this connection for my unit testing - again, a situation that would benefit from some kind of mocking? Besides , My public interface connects to the database defined in the external configuration file - It seems incorrect to use this connection for unit testing - Again , This situation will benefit from some kind of simulation ?
Solution :
Reference resources : https://stackoom.com/en/question/V6iP边栏推荐
- 每日一题-LeetCode1175-质数排列-数学
- Several methods of creating thread classes
- Use of STM32 expansion board temperature sensor and temperature humidity sensor
- 洗个冷水澡吧
- AcWing 885. Find the combination number I (recursive preprocessing)
- 1076 Forwards on Weibo
- [data recovery in North Asia] a data recovery case of raid crash caused by hard disk drop during data synchronization of hot spare disk of RAID5 disk array
- Some tools that research dogs may need
- Global and Chinese market of mainboard 2022-2028: Research Report on technology, participants, trends, market size and share
- 科研狗可能需要的一些工具
猜你喜欢
![[hard ten treasures] - 1 [basic knowledge] classification of power supply](/img/a8/f129c9d15ca6ed99db1dacfc750ead.png)
[hard ten treasures] - 1 [basic knowledge] classification of power supply

LeetCode1497-检查数组对是否可以被 k 整除-数组-哈希表-计数

技术分享| 融合调度中的广播功能设计

智慧运维:基于 BIM 技术的可视化管理系统

STM32扩展板 温度传感器和温湿度传感器的使用

如何选择导电滑环材料

Neural network convolution layer

Pytoch (III) -- function optimization

Leetcode522- longest special sequence ii- hash table - String - double pointer

Software intelligence: the "world" and "boundary" of AI sentient beings in AAAs system
随机推荐
LeetCode522-最长特殊序列II-哈希表-字符串-双指针
Matters behind the construction of paint testing laboratory
LeetCode_ 35 (search insertion position)
【暑期每日一题】洛谷 P1629 邮递员送信(未完待续...)
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
STM32扩展板 温度传感器和温湿度传感器的使用
智慧运维:基于 BIM 技术的可视化管理系统
Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode_ 58 (length of last word)
担心侵权?必备无版权素材网站分享,不用担心视频剪辑缺素材
js解决浮点数相乘精度丢失问题
AssertionError assert I.ndim == 4 and I.shape[1] == 3
Global and Chinese market of metal oxide semiconductor field effect transistors 2022-2028: Research Report on technology, participants, trends, market size and share
分布式-总结列表
Copier le matériel de conseils de bébé ne peut pas être vide, comment résoudre?
打印流与System.setout();
常用的Transforms中的方法
Global and Chinese market of enterprise wireless LAN 2022-2028: Research Report on technology, participants, trends, market size and share
[hard ten treasures] - 1 [basic knowledge] classification of power supply
FileInputStream