Let say your website need to call Twitter API to perform some tasks, you have several options:
Which one is the best approach if your services depends on the external api?
I would step back and ask yourself what you are trying to test.
If you are trying to test your other code in isolation, use a mock (that's the purpose of a mock after all).
If you are trying to really test end-to-end, use the production API (or a live test API if they have one).
So my answer is pretty close to your #2 choice, with the caveat that you should consider whether you need to test an API from a third party. Sometimes it makes sense to do so or is necessary, sometimes it doesn't make sense (they are known to be reliable or it's very inconvenient to do so).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With