When to use stubs and mocks?

后端 未结 5 701
既然无缘
既然无缘 2021-01-02 10:46

I\'ve this confusion all the time. If I write a code which uses fake code to assert some operation, how do i trust my real implementation when it is started really using the

5条回答
  •  独厮守ぢ
    2021-01-02 11:19

    Yes, using a real database would be more functional or integration testing, depending on your definition. Personally, I feel that unit tests are supposed to test exactly that method only, in isolation of everything else. So regardless of whether the session or the transaction works or not, your unit test must ensure that those objects will be called upon to do their work when and as necessary - that's where mocks and stubs come in. You use them to ensure that your unit test is as decoupled from external functionality so that it can be tested as a basic unit; ideally anyway.

提交回复
热议问题