Mocking DataSource for JdbcTemplate with Mockito

后端 未结 2 1296
-上瘾入骨i
-上瘾入骨i 2020-12-21 11:12

I\'m trying to test a class in a Spring project. I would like to make as many changes as possible in the test class vs. the dao class so that I don\'t have to retest all sor

2条回答
  •  眼角桃花
    2020-12-21 11:27

    If you're testing a DAO it makes no sense at all to mock the data source. What are you testing? You need to make a DAO that interacts with the database.

    Once you have that working, you're free to mock the interface-based DAO when testing services that use it. You've already tested the DAO; there's no reason to redo it when testing the services.

    I'd say you're off-track if you're mocking the data source when testing the DAO.

提交回复
热议问题