Let say your website need to call Twitter API to perform some tasks, you have several options:
- Only use mock
- Use mock in unit test, but use production api in integration test
- Only call production api, never use mock
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).