本文介绍了我应该使用内存数据库而不是模拟我的存储库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢在测试时使用内存数据库(例如SQLite)而不是为我的存储库创建Mocks的想法.这样,我还可以测试存储库的代码,而不会出现任何性能问题.

I like the idea of using an In-Memory Database such as SQLite when testing instead of creating Mocks for my Repositories. This way I can also test the code of my Repositories without any performance issues.

此策略的优缺点是什么?

What are the pros and cons of this strategy?

推荐答案

我会说这两种策略是两回事.就像您自己说的那样,使用内存数据库也可以测试存储库,但是,您必须先测试存储库才能实现关注点分离.在设计系统时(也许根据MVC),您需要在Models/Repository之前使用Controller,因为首先必须确定要执行的操作,然后才确定要共同实现该目标的实体.因此,也许首先创建控制器和模拟存储库是一种更好的方法,然后,如果确实很容易设置,则可以使用内存数据库测试存储库.

I would say those two strategies are two different things.As you said yourself, with in-memory db you can test your repositories as well, however, you have to test your repositories first to achieve separation of concerns. When you are designing your system, maybe according to the MVC, you want your Controllers before Models/Repositories, because firstly you have to decide what do you want to do and afterthat decide which entities will collaborativelly achieve that goal. So maybe creating controllers and mocking repositories first is a better way, afterwards you can test your repositories using the in-memory database if it is really easy to setup.

这篇关于我应该使用内存数据库而不是模拟我的存储库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 10:41