如果我为数据库调用编写测试,那么我正在编写单元测试或集成测试?
我开始编写数据库调用和查询的测试。但我想知道,既然它不依赖于任何其他函数,那么为数据库调用编写测试就是单元测试吗?
编辑:这是围绕 Node.js 环境的
I am starting to write tests for database calls and queries. But I was wondering, since it doesn't depend on any other function, then writing test for database calls are unit tests?
Edit: This is around a Node.js environment
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数据库与您正在测试的应用程序分离,因此,测试将是集成测试而不是单元测试。
请注意,单元测试仅限于处理隔离的单个软件。如果您明确想要对代码进行单元测试(而不进行实际的数据库调用),您可以使用模拟框架,例如 最小起订量。
The database is separate to the application that you are testing, and as such, the tests would be integration tests rather than unit tests.
Note that unit tests are limited to dealing with single pieces of software in isolation. If you explicitly want to unit test your code as it stands (without making actual database calls), you can make use of a mocking framework, such as Moq.