0
0
Microservicessystem_design~20 mins

Unit testing services in Microservices - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Unit Testing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why isolate dependencies in unit testing microservices?

In unit testing a microservice, why is it important to isolate its dependencies?

ATo deploy the microservice faster in production
BTo speed up the entire system by running all services simultaneously
CTo test the network latency between microservices
DTo ensure tests only verify the microservice's own logic without interference from other services
Attempts:
2 left
💡 Hint

Think about what unit testing aims to verify.

Architecture
intermediate
2:00remaining
Best practice for mocking external service calls in microservice unit tests

Which approach is best for mocking external service calls when unit testing a microservice?

AUse a mocking framework to replace external service calls with predefined responses
BUse a database snapshot to simulate external service data
CSkip testing external calls and only test internal methods
DCall the real external services to verify integration
Attempts:
2 left
💡 Hint

Consider how to keep unit tests fast and reliable.

scaling
advanced
3:00remaining
Scaling unit tests for a microservice with many dependencies

You have a microservice with many external dependencies. How can you scale unit testing effectively?

ATest only the main dependency and ignore others
BRun integration tests only and skip unit tests
CCreate mocks for all dependencies and use test doubles to simulate their behavior
DManually test the microservice in production environment
Attempts:
2 left
💡 Hint

Think about how to keep unit tests manageable and reliable.

tradeoff
advanced
3:00remaining
Tradeoff of using real databases vs mocks in microservice unit tests

What is a key tradeoff when choosing between using a real database or mocks in microservice unit tests?

AMocks always cause tests to fail; real databases never fail
BReal databases provide realistic tests but slow down test execution; mocks are faster but less realistic
CUsing real databases eliminates the need for unit tests
DMocks require more hardware resources than real databases
Attempts:
2 left
💡 Hint

Consider speed versus realism in tests.

estimation
expert
3:00remaining
Estimating test coverage impact of unit tests on a microservice with 10 endpoints

A microservice has 10 endpoints. Each endpoint has 5 main logic branches. If unit tests cover 80% of all branches, how many branches are tested?

A40
B50
C80
D100
Attempts:
2 left
💡 Hint

Calculate total branches and then apply coverage percentage.