What's the point of testing fake repositories?

后端 未结 3 1399
清歌不尽
清歌不尽 2021-02-14 20:08

I\'ve been trying to push my mentallity when developing at home to be geared more towards TDD and a bit DDD.

One thing I don\'t understand though is why you would creat

3条回答
  •  终归单人心
    2021-02-14 20:22

    As I see it there are two really big reasons why you test against faked resources:

    • It makes unit testing faster when you have a mocked up against slow I/O or database. This may not look like anything if you have a small test suite but when you're up to +500 unit tests it starts to make a difference. In such amount, tests that run against the database will start to take several seconds to do. Programmers are lazy and want things to go fast so if running a test suite takes more than 10 seconds then you won't be happy to do TDD anymore.
    • It enforces you to think about your code design to make changes easier. Design by contract and dependency injection also becomes so much easier to do if you've made implementation against interfaces or abstract classes. If done right such design makes it easier to comply to changes in your code.

    The only drawback is the obvious one:

    • How can you be sure it really works?

    ...and that is what integration tests are for.

提交回复
热议问题