Bird
0
0

How can you unit test a microservice method that depends on asynchronous calls to external APIs without slowing down your test suite?

hard📝 Trade-off Q9 of 15
Microservices - Testing Microservices
How can you unit test a microservice method that depends on asynchronous calls to external APIs without slowing down your test suite?
ASkip testing asynchronous parts
BUse real API calls but limit test frequency
CMock the asynchronous API calls with resolved promises
DRun tests only in production environment
Step-by-Step Solution
Solution:
  1. Step 1: Identify asynchronous dependency in method

    External API calls are asynchronous and slow down tests if real.
  2. Step 2: Use mocks returning resolved promises

    Mocking with resolved promises simulates async calls instantly.
  3. Final Answer:

    Mock the asynchronous API calls with resolved promises -> Option C
  4. Quick Check:

    Mock async calls with resolved promises [OK]
Quick Trick: Mock async calls with resolved promises for speed [OK]
Common Mistakes:
  • Using real API calls in unit tests
  • Skipping async parts and missing coverage
  • Running tests only in production

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes