Quantcast
Channel: What's the difference between a mock & stub? - Stack Overflow
Viewing all articles
Browse latest Browse all 43

Answer by Developer for What's the difference between a mock & stub?

$
0
0

Both Stubs and Mocks override external dependencies but the difference is

Stubs -> To Test Data

Mocks -> To Test Behavior

A quote from Fowler's Mocks Aren't Stubs article:

  • Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test.
  • Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive.

This obviously tells the difference.


Fake/Dummy -> Test nothing (just override functionality with empty methods, eg replace Logger to avoid any logging noise while testing)


Viewing all articles
Browse latest Browse all 43

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>