Does a Middle Ground Exist? (Unit Testing vs. Integration Testing)

拜拜、爱过 提交于 2019-12-05 15:41:57

It sounds like you're describing the testing of an implementation detail rather than fulfillment of the requirements of a pattern by an implementor of the pattern. It doesn't matter if "specific points of execution" have been reached within the tested unit, it only matters if the concrete implementor upholds the contract of the interface. It's perfectly acceptable for tests to create a T entity for testing purposes, that's what mocks are for.

If you want to do integration testing you need to use the real database. But if you quickly want to test things you could try an in memory database. The question is what you can test and what you cannot test. As long as your database access code is db specific you are using an external system (to stay in unit test speak) which you should mock. But since you really want to know if your data ends up in the datbase you need to test against the real database.

But if you use some db abstraction e.g. an ORM mapper you could use the ORM mapper and test if at least the mapping does work correctly. The ORM mapper then could use an in memory datbase for your tests to check if the ORM mapper does work as expected.

If you do not use an ORM mapper and you create an additional db abstraction layer only to have an abstraction so you have code which is executed for the sole purpose to have errors you want to uncover in your true unit tests is not going to make you more productive.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!