Mock Objects vs Test Database

后端 未结 6 1905
庸人自扰
庸人自扰 2021-02-19 20:42

What\'s the advantage of using mock objects in comparison to a static test database that has known data and using transactions to make sure nothing changes when testing against

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-19 21:08

    Firstly, using a mock will be much quicker than connecting to an external database. However the main reason is that mocks behave the same each time the test is run, which you can't guarentee with an external service like a database, which means unit tests don't fail randomly. You can also easily simulate any types of failure you want to handle with a mock object.

    It's also a good idea to run integration tests against a real database however to test things like configuration and performance.

提交回复
热议问题