Skip to content
Sharp

Testing · interview question

Which technique would you use to test a controller method that relies on a complex service layer with multiple dependencies?

Multiple choiceHardchapter-10-curatedpremiumtestingcontroller-testing
Choose one answer
Answer and explanation

Correct answer

C. Use @MockBean to mock the service layer dependencies

Why

@MockBean is used to create mock instances of dependencies in Spring tests, allowing you to isolate the controller's logic from the service layer. This enables testing only the behavior of the controller without invoking the actual service logic.

Test yourself on Testing

A free test with instant, explained results. No account needed.

Start free test
All Testing questions →