---
title: "Recursive Fakes"
url: "https://courses.osherove.com/courses/tdd-in-net-in-hebrew/recursive-fakes.md"
canonical: "https://courses.osherove.com/courses/tdd-in-net-in-hebrew/recursive-fakes/"
tags: []
author: "Roy Osherove"
description: "Lesson 11 of 22 in TDD in .NET in Hebrew (Day 2 - Mock Objects and TDD), 3:10. Free video by Roy Osherove."
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/"
---

# Recursive Fakes

1. [Courses](https://courses.osherove.com/#courses)
2. [TDD in .NET in Hebrew](https://courses.osherove.com/courses/tdd-in-net-in-hebrew/)
3. Day 2 - Mock Objects and TDD

Lesson 11 of 22

Duration: 3:10 [Watch on YouTube](https://www.youtube.com/watch?v=l-dwbnVu_qc) Spoken in Hebrew

## In this lesson

With [NSubstitute](https://osherove.com/blog/2012/6/26/fakeiteasy-or-nsubstitute-which-should-i-use-for-samples-in.html "FakeItEasy or NSubstitute? Which should I use for samples in art of unit testing 2nd edition? (osherove.com)"), Roy Osherove shows [recursive fakes](https://osherove.com/blog/2008/10/4/isolator-feature-focus-recursive-fakes.html "Isolator feature focus: Recursive Fakes (osherove.com)"): when a person object is faked, its manager property returns a [fake](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-4#ch04lev1sec2 "The difference between mocks and stubs (The Art of Unit Testing, 2nd ed., ch. 4)") as well, instead of each returned object being set up on its own line. He says [Isolator](https://osherove.com/blog/2009/7/9/minimizing-unit-test-fragility-8-features-in-typemock-isolat.html "Minimizing unit Test Fragility – 8 features in Typemock Isolator to help (osherove.com)") was the first framework to do this and that it makes tests more [maintainable](https://livebook.manning.com/book/the-art-of-unit-testing-third-edition/chapter-8 "Maintainability (The Art of Unit Testing, 3rd ed., ch. 8)"), because a new property or method that returns an object is faked by default. He then sends the group back to the exercises, up to the login manager that uses a static method.

## Transcript

367 words

[\[00:07\]](https://www.youtube.com/watch?v=l-dwbnVu_qc&t=7s) מה שאני יכול לקבל אוטומטית זה person שהמנדר שלו הוא גם פיק בלי לעשות את זה בשתי שורות זאת אומרת אם פעם רציתי שגם פרו נקודה מנגר אם רציתי שפה מנג'ר יהיה [פייק](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-4#ch04lev1sec2 "The difference between mocks and stubs (The Art of Unit Testing, 2nd ed., ch. 4)") הייתי צריך להגיד אם הייתי רוצה להגיד ככה, אם הייתי רוצה בוא כבר לא זוכר את הAPI כבר מתבלבל אה נכון when נכון

[\[00:38\]](https://www.youtube.com/watch?v=l-dwbnVu_qc&t=38s) פעם אם הייתי רוצה להגיד ככה P when manג'ר אה זה propפרerטy נכון אפילו לא צריך לעשות ספון מצטער שאני מבלבל אתכם פשוט אני לא רגיל לעבוד באמצע הפסידות בדרך כלל פיק זי אבל רציתי לעשות אם אני אעשה p manager לעשות aserט is not או

[\[01:19\]](https://www.youtube.com/watch?v=l-dwbnVu_qc&t=79s) מה שאני אמור לקבל פה זה שמנגר בי default הוא לא נעל ברגע שאני יש לי סבסיט לפרסם ותשימו לב שגם מנג'ר מקדם מנג'ר גם לא ינן גם המנג'ר שלו לא יובל פעם בטestטים לכל לכל פרופרטי או פונקציה שמחזירה אובייקט ורציתי שהוא יהיה פייק הייתי צריך להגדיר את זה בשורה היום הנושא של recקury fיקס הוא אחד הדברים השולטים הפרימוקט הראשון שעשה את זה דרך אגב היה אסוליטור והרעיון היה שאם יש לך משהו שכבר מחזיר אובייקט והot objectט שלך הוא פייק

[\[01:51\]](https://www.youtube.com/watch?v=l-dwbnVu_qc&t=111s) אז אז כל הרט object שלו הם [fake](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-5#ch05lev1sec2 "Dynamically creating a fake object (The Art of Unit Testing, 2nd ed., ch. 5)") by default ואז הest הרבה יותר [maintainable](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-8#ch08lev1sec2 "Writing maintainable tests (The Art of Unit Testing, 2nd ed., ch. 8)") אחרת אם מחר אני מוסיף עוד פרטי שלא אכפת לי ממנו בטestינג אבל מישהו משתמש בו אני צריך להגיד שהוא פ כדי שהוא יחזיר איזשהו ערך אחרת הטestטים הישנים של אולי הם פשוט מכשלים ככה by default ברגע שאני עושה substitute for person אז כל דבר שאפשר לעשות לו פיק הוא fake ואז אני יכול או לשנות את ההתנהגות שלו או שבדfaultט הוא פשוט [stub](https://livebook.manning.com/book/the-art-of-unit-testing-third-edition/chapter-3#sigil_toc_id_62 "Reasons to use stubs (The Art of Unit Testing, 3rd ed., ch. 3)") שמחזיר default vales זה החלק היפה שבשורה אחת אני אומר person אכפת לי ממנו אבל כל מה שפסון מחזיר לא אכפת לי עד שעד עד שיוכל אחרת ואם מחר יש לי פרפרטי חדש או פונקציה חדשה שמחזירה אובייקט עדיף אותם f ולא יקרה שום דבר אם מישהו יקרה להם אם מישהו יקרא להם את

[\[02:39\]](https://www.youtube.com/watch?v=l-dwbnVu_qc&t=159s) מה שאני מבקשת לעשות עכשיו זה שתמשיכו את ה את הז כולל maner 2 ולעשות את הCIז עד login manager with static זאת אומרת כשאתם מגיעים לפה לעצור ופה אנחנו נלמד עוד טכניקות בסדר אז להמשיך בבקשה את התרגילים עד מספר שמונה כולל שאלות דרך אגב שאלה ‏Ja.

## Related

- [Isolator feature focus: Recursive Fakes](https://osherove.com/blog/2008/10/4/isolator-feature-focus-recursive-fakes.html) · osherove.com

    Roy's post on Isolator's recursive fakes, the feature the lesson shows with NSubstitute and credits to Isolator.

- [Fake chains: stubs that produce mocks or other stubs](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-4#ch04lev1sec6) · The Art of Unit Testing, 2nd ed., ch. 4

    Fake chains: stubs that produce other stubs, the repetitive setup recursive fakes remove.

- [Features supporting future-proofing and usability](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-6#ch06lev1sec3) · The Art of Unit Testing, 2nd ed., ch. 6

    Book section on isolation framework features for future-proofing and usability, the maintainability benefit claimed here.

### Also linked in this lesson

#### The Art of Unit Testing, 3rd ed.

- [Maintainability](https://livebook.manning.com/book/the-art-of-unit-testing-third-edition/chapter-8), ch. 8
- [Reasons to use stubs](https://livebook.manning.com/book/the-art-of-unit-testing-third-edition/chapter-3#sigil_toc_id_62), ch. 3

#### The Art of Unit Testing, 2nd ed.

- [The difference between mocks and stubs](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-4#ch04lev1sec2), ch. 4
- [Dynamically creating a fake object](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-5#ch05lev1sec2), ch. 5
- [Writing maintainable tests](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-8#ch08lev1sec2), ch. 8

#### osherove.com

- [FakeItEasy or NSubstitute? Which should I use for samples in art of unit testing 2nd edition?](https://osherove.com/blog/2012/6/26/fakeiteasy-or-nsubstitute-which-should-i-use-for-samples-in.html)
- [Minimizing unit Test Fragility – 8 features in Typemock Isolator to help](https://osherove.com/blog/2009/7/9/minimizing-unit-test-fragility-8-features-in-typemock-isolat.html)

[Previous lesson Advanced Mocks and Stubs](https://courses.osherove.com/courses/tdd-in-net-in-hebrew/advanced-mocks-and-stubs/) [Next lesson Legacy Refactoring intro](https://courses.osherove.com/courses/tdd-in-net-in-hebrew/legacy-refactoring-intro/)


---

## 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/
