The repository itself is not usually tested?

后端 未结 4 1146
你的背包
你的背包 2020-11-28 08:19

I\'m sorry but I\'m new to repositories patterns, unit tests and orm tools.

I\'ve been researching on unit tests and the repository pattern, and arrived at some conc

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 08:51

    When Unit Testing you need to be clear what "Unit" you are testing. You mock things that are outside of your Unit while you test your Unit. Things you mock may themselves be tested separately.

    There's another kind of testing where you test larger pieces. So you might test your code + repository + database. There's value in that but it's not testing the same things. In particular when using a real database it's harder to force your code down some error paths.

    Should you test {your code + repository} and mock the database? Depends how complex and how well-tested the repository is in its own right.

提交回复
热议问题