当前位置:网站首页>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边栏推荐
- Principle, technology and implementation scheme of data consistency in distributed database
- Software intelligence: the "world" and "boundary" of AI sentient beings in AAAs system
- 解决qiankun中子应用外链文件无法获取
- 【暑期每日一题】洛谷 P1629 邮递员送信(未完待续...)
- [daily question in summer] Luogu p7222 [rc-04] informatics competition
- 解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key
- 分布式数据库数据一致性的原理、与技术实现方案
- LeetCode522-最长特殊序列II-哈希表-字符串-双指针
- STM32 extended key scan
- Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
随机推荐
pytorch中常用数据集的使用方法
如何开始学剪辑?零基础详细解析
[NLP Li Hongyi] notes
解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key
【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
RuntimeError: mean(): input dtype should be either floating point or complex dtypes. Got Long instead
Detailed explanation of distributed global unique ID solution
Character input stream and character output stream
Single page application
分布式数据库数据一致性的原理、与技术实现方案
解决qiankun中子应用外链文件无法获取
Basic skeleton of neural network nn Use of moudle
Global and Chinese market of protection circuit modules 2022-2028: Research Report on technology, participants, trends, market size and share
Several methods of creating thread classes
AcWing 888. Finding combinatorial number IV (the problem of finding combinatorial number with high precision)
1076 Forwards on Weibo
AcWing 885. Find the combination number I (recursive preprocessing)
[FTP] the solution to "227 entering passive mode" during FTP connection
Global and Chinese market of solder wire 2022-2028: Research Report on technology, participants, trends, market size and share
Oracle views the creation time of the tablespace in the database









