Mock object

Hiroyuki Ohnaka
Hiroyuki OhnakaGrowth xPartners Incorporated.
Mock Object




2011   3   5
How it works

               SUT

               Mock Object   SUT




2011   3   5
When to use it

               Untested Requirement
                   (pp.273)




                                 ↑

2011   3   5
Mock Object
                          Test Stub


                                      equals


                                                   Mock Object


                 equals                        →Equality Pollution
               (pp.217)




2011   3   5
Mock Object                  Equality
               Assertions           comparator




               Mock Object




                     Mock Object   Mock Object


                              Mock Object



2011   3   5
Implementation Notes

               Mock Object        SUT




                      Test Spy



2011   3   5
Mock Object                       4
                      fixture
                      3
                          result verification phase
                  (“final verification”
                  )




2011   3   5
Fixture Setup
               MockObject         /


               Exercise SUT
               MocK Object


               Result verification
                        “final verification”


               Fixture teardown




2011   3   5
Construction
               Four-Phase Test   fixture setup phase
                        Mock Object




               Configuration with Expected Values
               Test Double                     Mock
               Object


               →Hard-Coded Test Double


2011   3   5
Installation
               Test Double SUT




               SUT


               Dependency Injection   Dependency Lookup




2011   3   5
Usage
               SUT Mock Object




               Assertion
               (      Mock Object


                                    )


2011   3   5
Mock Object   SUT


                             →happy path




2011   3   5
Final Verification
                          1


                         Mock Object toolkits    teardown


                                       final Verification
               Method




2011   3   5
Motivating Example




2011   3   5
Refactoring Notes
                       Test Double

               Mock Object
                                 SUT



                             Mock Object                 1
                                     final verification method




2011   3   5
2011   3   5
2011   3   5
JUnit3      Mock Object    TestCase
                                    Assertion Method   static




                   xUnit Family      NUnit   static
                         Assert


                  Ruby Test::Unit        mixins
               Assert



2011   3   5
Example: Mock Object
               (Dynamically Generated)




2011   3   5
Further Reading

                  xUnit                Mock Object


                                        Mock Object
               Test Stub Fake Object


                →Appnendix B(pp.741)



2011   3   5
1 of 20

Recommended

Functions by
FunctionsFunctions
FunctionsMichael Gordon
801 views7 slides
Junit Recipes - Elementary tests (1/2) by
Junit Recipes  - Elementary tests (1/2)Junit Recipes  - Elementary tests (1/2)
Junit Recipes - Elementary tests (1/2)Will Shen
367 views18 slides
CORE JAVA by
CORE JAVACORE JAVA
CORE JAVAShohan Ahmed
3.6K views6 slides
Csharp by
CsharpCsharp
CsharpVenkat Sanaka
83 views2 slides
2CPP18 - Modifiers by
2CPP18 - Modifiers2CPP18 - Modifiers
2CPP18 - ModifiersMichael Heron
385 views23 slides
STL Algorithms In Action by
STL Algorithms In ActionSTL Algorithms In Action
STL Algorithms In ActionNorthwest C++ Users' Group
841 views99 slides

More Related Content

What's hot

Unit testing.pptx [repaired] by
Unit testing.pptx [repaired]Unit testing.pptx [repaired]
Unit testing.pptx [repaired]Mohammad Asmar
230 views19 slides
What's new in c# 6.0 by
What's new in c# 6.0What's new in c# 6.0
What's new in c# 6.0LearningTech
579 views35 slides
2. Design patterns. part #2 by
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2Leonid Maslov
281 views25 slides
The Use of Static Code Analysis When Teaching or Developing Open-Source Software by
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareThe Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareAndrey Karpov
50 views51 slides
Templates exception handling by
Templates exception handlingTemplates exception handling
Templates exception handlingsanya6900
1.7K views28 slides
A Proposal to Orchestrate Test Cases by
A Proposal to Orchestrate Test CasesA Proposal to Orchestrate Test Cases
A Proposal to Orchestrate Test CasesBoni García
323 views22 slides

What's hot(20)

Unit testing.pptx [repaired] by Mohammad Asmar
Unit testing.pptx [repaired]Unit testing.pptx [repaired]
Unit testing.pptx [repaired]
Mohammad Asmar230 views
What's new in c# 6.0 by LearningTech
What's new in c# 6.0What's new in c# 6.0
What's new in c# 6.0
LearningTech579 views
2. Design patterns. part #2 by Leonid Maslov
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
Leonid Maslov281 views
The Use of Static Code Analysis When Teaching or Developing Open-Source Software by Andrey Karpov
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareThe Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
Andrey Karpov50 views
Templates exception handling by sanya6900
Templates exception handlingTemplates exception handling
Templates exception handling
sanya69001.7K views
A Proposal to Orchestrate Test Cases by Boni García
A Proposal to Orchestrate Test CasesA Proposal to Orchestrate Test Cases
A Proposal to Orchestrate Test Cases
Boni García323 views
Xp Day 080506 Unit Tests And Mocks by guillaumecarre
Xp Day 080506 Unit Tests And MocksXp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And Mocks
guillaumecarre846 views
Mining Fix Patterns for FindBugs Violations by Dongsun Kim
Mining Fix Patterns for FindBugs ViolationsMining Fix Patterns for FindBugs Violations
Mining Fix Patterns for FindBugs Violations
Dongsun Kim641 views
Covariance, contravariance 觀念分享 by LearningTech
Covariance, contravariance 觀念分享Covariance, contravariance 觀念分享
Covariance, contravariance 觀念分享
LearningTech412 views
Java 8 Functional Programming - I by Ugur Yeter
Java 8 Functional Programming - IJava 8 Functional Programming - I
Java 8 Functional Programming - I
Ugur Yeter187 views
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated... by Iosif Itkin
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
Iosif Itkin3K views
Software Engineering - Module 3: Lesson7 by ArraLafuente
Software Engineering - Module 3: Lesson7Software Engineering - Module 3: Lesson7
Software Engineering - Module 3: Lesson7
ArraLafuente155 views
QTP Automation Testing Tutorial 5 by Akash Tyagi
QTP Automation Testing Tutorial 5QTP Automation Testing Tutorial 5
QTP Automation Testing Tutorial 5
Akash Tyagi306 views
White Box Testing (Introduction to) by Henry Muccini
White Box Testing (Introduction to)White Box Testing (Introduction to)
White Box Testing (Introduction to)
Henry Muccini1.2K views

Viewers also liked

Mock Objects Presentation by
Mock Objects PresentationMock Objects Presentation
Mock Objects PresentationAndriy Buday
864 views10 slides
Beyond TDD by
Beyond TDDBeyond TDD
Beyond TDDBen Carey
607 views54 slides
Mock objects - Teste de código com dependências by
Mock objects - Teste de código com dependênciasMock objects - Teste de código com dependências
Mock objects - Teste de código com dependênciasDenis L Presciliano
923 views14 slides
Testing with Mock Objects by
Testing with Mock ObjectsTesting with Mock Objects
Testing with Mock ObjectsBen Carey
943 views23 slides
TDD and mock objects by
TDD and mock objectsTDD and mock objects
TDD and mock objectsSteve Zhang
1.4K views28 slides
Easymock Tutorial by
Easymock TutorialEasymock Tutorial
Easymock TutorialSbin m
20.9K views25 slides

Viewers also liked(8)

Mock Objects Presentation by Andriy Buday
Mock Objects PresentationMock Objects Presentation
Mock Objects Presentation
Andriy Buday864 views
Beyond TDD by Ben Carey
Beyond TDDBeyond TDD
Beyond TDD
Ben Carey607 views
Mock objects - Teste de código com dependências by Denis L Presciliano
Mock objects - Teste de código com dependênciasMock objects - Teste de código com dependências
Mock objects - Teste de código com dependências
Testing with Mock Objects by Ben Carey
Testing with Mock ObjectsTesting with Mock Objects
Testing with Mock Objects
Ben Carey943 views
TDD and mock objects by Steve Zhang
TDD and mock objectsTDD and mock objects
TDD and mock objects
Steve Zhang1.4K views
Easymock Tutorial by Sbin m
Easymock TutorialEasymock Tutorial
Easymock Tutorial
Sbin m20.9K views
Advanced PHPUnit Testing by Mike Lively
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit Testing
Mike Lively23.6K views

More from Hiroyuki Ohnaka

remote Docker over SSHが熱い by
remote Docker over SSHが熱いremote Docker over SSHが熱い
remote Docker over SSHが熱いHiroyuki Ohnaka
708 views11 slides
VSCode Remote Container & GitHub Codespacesで拓く次世代のJava開発体験 by
VSCode Remote Container & GitHub Codespacesで拓く次世代のJava開発体験VSCode Remote Container & GitHub Codespacesで拓く次世代のJava開発体験
VSCode Remote Container & GitHub Codespacesで拓く次世代のJava開発体験Hiroyuki Ohnaka
672 views23 slides
Remote Development with Visual Studio Code & A clean dev env, working every ... by
Remote Development with Visual Studio Code &  A clean dev env, working every ...Remote Development with Visual Studio Code &  A clean dev env, working every ...
Remote Development with Visual Studio Code & A clean dev env, working every ...Hiroyuki Ohnaka
455 views13 slides
ChefとItamaeをニコイチしてAnsibleにマイグレーションした話 by
ChefとItamaeをニコイチしてAnsibleにマイグレーションした話ChefとItamaeをニコイチしてAnsibleにマイグレーションした話
ChefとItamaeをニコイチしてAnsibleにマイグレーションした話Hiroyuki Ohnaka
1.1K views41 slides
「WindowsデスクトップでWeb開発 改訂版」サンプル by
「WindowsデスクトップでWeb開発 改訂版」サンプル「WindowsデスクトップでWeb開発 改訂版」サンプル
「WindowsデスクトップでWeb開発 改訂版」サンプルHiroyuki Ohnaka
672 views24 slides
Mackerelの薄い本 by
Mackerelの薄い本Mackerelの薄い本
Mackerelの薄い本Hiroyuki Ohnaka
2K views18 slides

More from Hiroyuki Ohnaka(20)

VSCode Remote Container & GitHub Codespacesで拓く次世代のJava開発体験 by Hiroyuki Ohnaka
VSCode Remote Container & GitHub Codespacesで拓く次世代のJava開発体験VSCode Remote Container & GitHub Codespacesで拓く次世代のJava開発体験
VSCode Remote Container & GitHub Codespacesで拓く次世代のJava開発体験
Hiroyuki Ohnaka672 views
Remote Development with Visual Studio Code & A clean dev env, working every ... by Hiroyuki Ohnaka
Remote Development with Visual Studio Code &  A clean dev env, working every ...Remote Development with Visual Studio Code &  A clean dev env, working every ...
Remote Development with Visual Studio Code & A clean dev env, working every ...
Hiroyuki Ohnaka455 views
ChefとItamaeをニコイチしてAnsibleにマイグレーションした話 by Hiroyuki Ohnaka
ChefとItamaeをニコイチしてAnsibleにマイグレーションした話ChefとItamaeをニコイチしてAnsibleにマイグレーションした話
ChefとItamaeをニコイチしてAnsibleにマイグレーションした話
Hiroyuki Ohnaka1.1K views
「WindowsデスクトップでWeb開発 改訂版」サンプル by Hiroyuki Ohnaka
「WindowsデスクトップでWeb開発 改訂版」サンプル「WindowsデスクトップでWeb開発 改訂版」サンプル
「WindowsデスクトップでWeb開発 改訂版」サンプル
Hiroyuki Ohnaka672 views
Microsoft DocsにContributeした話 by Hiroyuki Ohnaka
Microsoft DocsにContributeした話Microsoft DocsにContributeした話
Microsoft DocsにContributeした話
Hiroyuki Ohnaka940 views
技術書典4 く-35「錬金術MeetUp」 Alchemist Vol.1 サンプル版 by Hiroyuki Ohnaka
 技術書典4  く-35「錬金術MeetUp」 Alchemist Vol.1 サンプル版 技術書典4  く-35「錬金術MeetUp」 Alchemist Vol.1 サンプル版
技術書典4 く-35「錬金術MeetUp」 Alchemist Vol.1 サンプル版
Hiroyuki Ohnaka2.6K views
4/22 技術書典4 か-16「ふぃーるどのーつ」 新刊「すいーとみゅーじっく vol.5Mackerelではじめるお手軽サーバー監視」サンプル版 by Hiroyuki Ohnaka
4/22 技術書典4 か-16「ふぃーるどのーつ」 新刊「すいーとみゅーじっく vol.5Mackerelではじめるお手軽サーバー監視」サンプル版4/22 技術書典4 か-16「ふぃーるどのーつ」 新刊「すいーとみゅーじっく vol.5Mackerelではじめるお手軽サーバー監視」サンプル版
4/22 技術書典4 か-16「ふぃーるどのーつ」 新刊「すいーとみゅーじっく vol.5Mackerelではじめるお手軽サーバー監視」サンプル版
Hiroyuki Ohnaka737 views
仮想通貨始めました~GethではじめるEthereum~ by Hiroyuki Ohnaka
仮想通貨始めました~GethではじめるEthereum~仮想通貨始めました~GethではじめるEthereum~
仮想通貨始めました~GethではじめるEthereum~
Hiroyuki Ohnaka1.3K views
錬金術MeetUpへのお誘い by Hiroyuki Ohnaka
錬金術MeetUpへのお誘い錬金術MeetUpへのお誘い
錬金術MeetUpへのお誘い
Hiroyuki Ohnaka1.5K views
Mackerelではじめる お手軽サーバー監視 by Hiroyuki Ohnaka
Mackerelではじめる お手軽サーバー監視Mackerelではじめる お手軽サーバー監視
Mackerelではじめる お手軽サーバー監視
Hiroyuki Ohnaka4.1K views
「GebとSpockではじめるシステムテスト自動化」 by Hiroyuki Ohnaka
「GebとSpockではじめるシステムテスト自動化」「GebとSpockではじめるシステムテスト自動化」
「GebとSpockではじめるシステムテスト自動化」
Hiroyuki Ohnaka9.8K views
TDDはじめて物語Second Season(updated) by Hiroyuki Ohnaka
TDDはじめて物語Second Season(updated)TDDはじめて物語Second Season(updated)
TDDはじめて物語Second Season(updated)
Hiroyuki Ohnaka1.3K views
TDDはじめて物語 Second Season #tddbc by Hiroyuki Ohnaka
TDDはじめて物語 Second Season #tddbcTDDはじめて物語 Second Season #tddbc
TDDはじめて物語 Second Season #tddbc
Hiroyuki Ohnaka4.3K views
XP祭り2017 LT 「DevOps再考」(改題) by Hiroyuki Ohnaka
XP祭り2017 LT 「DevOps再考」(改題)XP祭り2017 LT 「DevOps再考」(改題)
XP祭り2017 LT 「DevOps再考」(改題)
Hiroyuki Ohnaka2.6K views
JDK9の真の目玉機能はこれだ! by Hiroyuki Ohnaka
JDK9の真の目玉機能はこれだ!JDK9の真の目玉機能はこれだ!
JDK9の真の目玉機能はこれだ!
Hiroyuki Ohnaka2.9K views
Java8移行は怖くない~エンタープライズ案件でのJava8移行事例~ by Hiroyuki Ohnaka
Java8移行は怖くない~エンタープライズ案件でのJava8移行事例~Java8移行は怖くない~エンタープライズ案件でのJava8移行事例~
Java8移行は怖くない~エンタープライズ案件でのJava8移行事例~
Hiroyuki Ohnaka10.3K views
「すいーとみゅーじっく」のできるまで by Hiroyuki Ohnaka
「すいーとみゅーじっく」のできるまで「すいーとみゅーじっく」のできるまで
「すいーとみゅーじっく」のできるまで
Hiroyuki Ohnaka904 views

Recently uploaded

The details of description: Techniques, tips, and tangents on alternative tex... by
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...BookNet Canada
121 views24 slides
Voice Logger - Telephony Integration Solution at Aegis by
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at AegisNirmal Sharma
17 views1 slide
PharoJS - Zürich Smalltalk Group Meetup November 2023 by
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023Noury Bouraqadi
120 views17 slides
Black and White Modern Science Presentation.pptx by
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptxmaryamkhalid2916
14 views21 slides
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院IttrainingIttraining
34 views8 slides
HTTP headers that make your website go faster - devs.gent November 2023 by
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023Thijs Feryn
19 views151 slides

Recently uploaded(20)

The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma17 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi120 views
Black and White Modern Science Presentation.pptx by maryamkhalid2916
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptx
maryamkhalid291614 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn19 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada130 views
Web Dev - 1 PPT.pdf by gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet55 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
6g - REPORT.pdf by Liveplex
6g - REPORT.pdf6g - REPORT.pdf
6g - REPORT.pdf
Liveplex9 views
Spesifikasi Lengkap ASUS Vivobook Go 14 by Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf

Mock object

  • 2. How it works SUT Mock Object SUT 2011 3 5
  • 3. When to use it Untested Requirement (pp.273) ↑ 2011 3 5
  • 4. Mock Object Test Stub equals Mock Object equals →Equality Pollution (pp.217) 2011 3 5
  • 5. Mock Object Equality Assertions comparator Mock Object Mock Object Mock Object Mock Object 2011 3 5
  • 6. Implementation Notes Mock Object SUT Test Spy 2011 3 5
  • 7. Mock Object 4 fixture 3 result verification phase (“final verification” ) 2011 3 5
  • 8. Fixture Setup MockObject / Exercise SUT MocK Object Result verification “final verification” Fixture teardown 2011 3 5
  • 9. Construction Four-Phase Test fixture setup phase Mock Object Configuration with Expected Values Test Double Mock Object →Hard-Coded Test Double 2011 3 5
  • 10. Installation Test Double SUT SUT Dependency Injection Dependency Lookup 2011 3 5
  • 11. Usage SUT Mock Object Assertion ( Mock Object ) 2011 3 5
  • 12. Mock Object SUT →happy path 2011 3 5
  • 13. Final Verification 1 Mock Object toolkits teardown final Verification Method 2011 3 5
  • 15. Refactoring Notes Test Double Mock Object SUT Mock Object 1 final verification method 2011 3 5
  • 16. 2011 3 5
  • 17. 2011 3 5
  • 18. JUnit3 Mock Object TestCase Assertion Method static xUnit Family NUnit static Assert Ruby Test::Unit mixins Assert 2011 3 5
  • 19. Example: Mock Object (Dynamically Generated) 2011 3 5
  • 20. Further Reading xUnit Mock Object Mock Object Test Stub Fake Object →Appnendix B(pp.741) 2011 3 5