CS FundamentalsVery hardGATE CS · TCS NQT Prime · Product Company SDE
What is the difference between a mock and a stub in unit testing terminology?
- A. A stub always throws an exception; a mock never does
- B. They are exactly the same thing with different names
- C. A stub simply returns canned responses to calls it receives; a mock additionally lets the test verify that specific calls were actually made to it, with specific arguments
- D. A mock can only be used for databases; a stub only for network calls
Correct answer: C. A stub simply returns canned responses to calls it receives; a mock additionally lets the test verify that specific calls were actually made to it, with specific arguments
Stubs are concerned with providing indirect input to the system under test (canned return values); mocks additionally support behaviour verification, letting the test assert that particular interactions happened.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A build pipeline fails a merge if the newly added code's test coverage for that specific change falls below a configured threshold…
- In Kanban's 'cumulative flow diagram', a widening band for a particular stage over time most directly indicates:
- A control-flow graph has 22 edges, 16 nodes and 1 connected component. Using V(G) = E − N + 2P, what is its cyclomatic complexity?
- A Scrum team completed 37, 16, 17 story points in its last 3 sprints. The remaining backlog is 140 points. Using average velocity, how…
- Why is 'testing in production' (e.g. canary releases combined with real monitoring) increasingly used alongside, not instead of…
- Why do many Agile teams deliberately re-estimate story points for a backlog item as more is learned about it, rather than treating the…