---
title: "Mocks and Stubs - The difference is in the flow of information"
url: "https://osherove.com/blog/2007/9/16/mocks-and-stubs-the-difference-is-in-the-flow-of-information.md"
canonical: "https://osherove.com/blog/2007/9/16/mocks-and-stubs-the-difference-is-in-the-flow-of-information.html"
published: "2007-09-16T15:26:55"
updated: "2007-09-16T15:26:55"
tags: ["Agile", "Agile Related", "Art Of Unit Testing", "Testing Guidelines", "Unit Testing"]
author: "Roy Osherove"
description: "In class today when explaining the difference between stubs and mocks, I realized a simple explanation to this: Stubs and mocks may seem the same but the flow of information from each is very different. Stubs provide…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Mocks and Stubs - The difference is in the flow of information

By Roy Osherove September 16, 2007 In [Agile](https://osherove.com/blog/category/agile), [Agile Related](https://osherove.com/blog/category/agile-related), [Art Of Unit Testing](https://osherove.com/blog/category/art-of-unit-testing), [Testing Guidelines](https://osherove.com/blog/category/testing-guidelines), [Unit Testing](https://osherove.com/blog/category/unit-testing)

**Historical article** · Originally published September 16, 2007; technical details may be outdated.

In class today when explaining the difference between stubs and mocks, I realized a simple explanation to this:

Stubs and mocks may seem the same but the flow of information from each is very different.

- Stubs provide input for the application under test so that the test can be performed on something else.
- Mocks provide input to the test to decide on pass\\fail. the opposite direction.

The following diagram shows the flow of critical information:

![image](https://osherove.com/img/wb/t_blogs_rosherove_WindowsLiveWriter_MocksandStubsThedifferenceisintheflowofi_149B8_image_thumb_1.png)

The red arrows signify the "critical" flow of information that is used to decide if the test had passed. A stub can never fail a test, so there is no flow of information back to the test. the mock records things and then tells our test if it's expectations have been met according to its recording.

A stub is application facing, and a mock is test facing. [Here's a more in depth overview of the two](http://martinfowler.com/articles/mocksArentStubs.html), but I haven't seen this explained as I just did anywhere. It's important to know and distinguish the two since many frameworks for mocking use these terms for different kinds of objects.

## Lessons on this topic

- [Introduction to Hand Written Fakes, Mocks and Stubs](https://courses.osherove.com/courses/the-art-of-unit-testing-and-tdd-master-class-in-net/introduction-to-hand-written-fakes-mocks-and-stubs/) · The Art of Unit Testing & TDD Master Class in .NET
- [Terminology](https://courses.osherove.com/courses/the-art-of-unit-testing-and-tdd-in-java/terminology/) · The Art of Unit Testing and TDD in Java
- [Summary Day 1](https://courses.osherove.com/courses/tdd-in-net-in-hebrew/summary-day-1/) · TDD in .NET in Hebrew

## More in Agile

[All posts in Agile](https://osherove.com/blog/category/agile)

- Sep 18, 2007

    ### [The Art Of Unit Testing - Help me choose a book cover](https://osherove.com/blog/2007/9/18/the-art-of-unit-testing-help-me-choose-a-book-cover.html)

- Sep 18, 2007

    ### [TDD Pattern: Composite Logic Development and Testing](https://osherove.com/blog/2007/9/18/tdd-pattern-composite-logic-development-and-testing.html)

- Sep 13, 2007

    ### [Throw-Away Tests Vs. Tests that Last](https://osherove.com/blog/2007/9/13/throw-away-tests-vs-tests-that-last.html)

- Sep 11, 2007

    ### [Scrum is not enough. Try ScrumP](https://osherove.com/blog/2007/9/11/scrum-is-not-enough-try-scrump.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
