Loading...
Loading...
Browse 4 real-world technical and behavioral interview questions about Mocking. Review scenarios, edge cases, and architectural best practices.
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.
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.
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.
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.