当前位置:网站首页>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边栏推荐
- C#读写应用程序配置文件App.exe.config,并在界面上显示
- [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
- AcWing 886. Finding combinatorial number II (pretreatment factorial)
- 解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *
- Character input stream and character output stream
- STM32扩展板 温度传感器和温湿度传感器的使用
- Pytorch convolution operation
- JS random verification code
- STM32扩展板 数码管显示
- Buffer stream and transform stream
猜你喜欢

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

複制寶貝提示材質不能為空,如何解决?

Use of dataloader

复制宝贝提示材质不能为空,如何解决?

Distributed architecture system splitting principles, requirements and microservice splitting steps

每日一题-LeetCode1175-质数排列-数学

Go learning notes (5) basic types and declarations (4)

C#读写应用程序配置文件App.exe.config,并在界面上显示

Detailed explanation of distributed global unique ID solution

STM32扩展板 数码管显示
随机推荐
最长递增子序列及最优解、动物总重量问题
Global and Chinese markets of InGaAs APD arrays 2022-2028: Research Report on technology, participants, trends, market size and share
Single page application
Dataloader的使用
Go learning notes (5) basic types and declarations (4)
[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
Global and Chinese market of mainboard 2022-2028: Research Report on technology, participants, trends, market size and share
How to hide browser network IP address and modify IP internet access?
Global and Chinese markets for business weather forecasting 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode_ 66 (plus one)
Matters behind the construction of paint testing laboratory
Several methods of creating thread classes
Global and Chinese market of paper machine systems 2022-2028: Research Report on technology, participants, trends, market size and share
如何开始学剪辑?零基础详细解析
Neural networks - use sequential to build neural networks
Global and Chinese market of broadband amplifiers 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode_66(加一)
Basic skeleton of neural network nn Use of moudle
【暑期每日一题】洛谷 P5740【深基7.例9】最厉害的学生
线程安全问题