Skip to content
Preptima

Top 4 Mocking Interview Questions

Browse 4 real-world technical and behavioral interview questions about Mocking. Review scenarios, edge cases, and architectural best practices.

You own the API test suite for a service from scratch. How do you structure it, and what do you mock?

Separate contract tests, which check shape and backwards compatibility cheaply, from integration tests that exercise real behaviour across real dependencies. Make every test create and own its data so the suite is re-runnable, spend most of your negative cases on authorisation and malformed input.

harddesign

Your suite mocks the database, every test passes, and the release still broke. What should you have tested instead?

A mock encodes your belief about the collaborator, so asserting against it proves the code matches your belief rather than reality. Use autospec so signatures are checked, and put a small number of tests against the real engine at the boundary the mock replaced. Use this mocking answer to show the decision, trade-off, and evidence rather than a memorised definition.

mediumconcept

Your test still reaches the network even though you patched the client. Talk me through fixture scope, parametrisation, and where a patch has to point.

A patch must replace the name in the module under test, because a from-import binds its own reference that the original module never consults again. Fixture scope is a shared lifetime, parametrisation belongs on the inputs rather than the assertions, and coverage records execution, not verification.

mediumconcept

How do you test a Node service, and what do you refuse to mock?

Drive business logic through injected dependencies rather than module mocks, intercept at the process boundary for outbound HTTP and time, and use a real database in a container for anything where the database is the logic — SQL, constraints, transactions and migrations.

mediumconcept