ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Steve Loughran
stevel@hortonworks.com
@steveloughran
I hate mocking
I hate mocking
I hate mocking
I hate mocking
when(mockClient
.initiateMultipartUpload(any(InitiateMultipartUploadRequest.class)))
.thenAnswer(new Answer<InitiateMultipartUploadResult>() {
@Override
public InitiateMultipartUploadResult answer(
InvocationOnMock invocation) throws Throwable {
LOG.debug("initiateMultipartUpload for {}", mockClient);
synchronized (lock) {
if (results.requests.size() == errors.failOnInit) {
if (errors.recover) errors.failOnInit(-1);
throw new AmazonClientException("Fail on init " + results.requests.size());
}
String uploadId = UUID.randomUUID().toString();
results.requests.put(uploadId, invocation.getArgumentAt(
0, InitiateMultipartUploadRequest.class));
results.uploads.add(uploadId);
return newResult(results.requests.get(uploadId), uploadId);
}
}
});
? Mock code reflects our assumptions about system behaviour
? Doesn't verify that the caller would work against real service
? Any change in real code breaks the tests: false positives
? Test failures often "fixed" by editing test/mock
... which could hide real problems
Why bother? It's high-maintenance suffering
I hate mocking
Proposed
? Avoid mock tests
? Add functional tests against real infrastructure
? Embed fault injection ability into functional code
? Use for integration testing
Ad

Recommended

Python: the coolest is yet to come
Python: the coolest is yet to come
Pablo Enfedaque
?
Unit testing with mock libs
Unit testing with mock libs
Valentin Kolesnikov
?
Implicit and Explicit waits in Selenium WebDriwer, how to.
Implicit and Explicit waits in Selenium WebDriwer, how to.
Yaroslav Pernerovsky
?
WebDriver Waits
WebDriver Waits
Yaroslav Pernerovsky
?
Automation puzzlers
Automation puzzlers
Yaroslav Pernerovsky
?
Martin Anderson - threads v actors
Martin Anderson - threads v actors
bloodredsun
?
Developed your first Xamarin.Forms Application
Developed your first Xamarin.Forms Application
Cheah Eng Soon
?
Testing with Kotlin
Testing with Kotlin
Robert Fletcher
?
The Ring programming language version 1.2 book - Part 28 of 84
The Ring programming language version 1.2 book - Part 28 of 84
Mahmoud Samir Fayed
?
Easy Button
Easy Button
Adam Dale
?
Android App Development - 07 Threading
Android App Development - 07 Threading
Diego Grancini
?
JS and patterns
JS and patterns
David Rodenas
?
VisualStudio2012-WhatsNew-TechEd_v3-9
VisualStudio2012-WhatsNew-TechEd_v3-9
SSW
?
¶ÅÔöÇ¿-¹ó±ô±ð³æ3×é¼þÉúÃüÖÜÆÚ
¶ÅÔöÇ¿-¹ó±ô±ð³æ3×é¼þÉúÃüÖÜÆÚ
ÔöÇ¿ ¶Å
?
Testing in android
Testing in android
jtrindade
?
ASP.NET MVC Internals
ASP.NET MVC Internals
Vitaly Baum
?
Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2
Fabio Collini
?
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWT
David Chandler
?
Reliability and Reslience
Reliability and Reslience
Donald Belcham
?
Testing with Containers
Testing with Containers
Romain Baugue
?
Android architecture component - FbCircleDev Yogyakarta Indonesia
Android architecture component - FbCircleDev Yogyakarta Indonesia
Pratama Nur Wijaya
?
Hadoop Vectored IO
Hadoop Vectored IO
Steve Loughran
?
The age of rename() is over
The age of rename() is over
Steve Loughran
?
What does Rename Do: (detailed version)
What does Rename Do: (detailed version)
Steve Loughran
?
Put is the new rename: San Jose Summit Edition
Put is the new rename: San Jose Summit Edition
Steve Loughran
?
@Dissidentbot: dissent will be automated!
@Dissidentbot: dissent will be automated!
Steve Loughran
?
PUT is the new rename()
PUT is the new rename()
Steve Loughran
?
Extreme Programming Deployed
Extreme Programming Deployed
Steve Loughran
?
Testing
Testing
Steve Loughran
?
What does rename() do?
What does rename() do?
Steve Loughran
?

More Related Content

What's hot (13)

The Ring programming language version 1.2 book - Part 28 of 84
The Ring programming language version 1.2 book - Part 28 of 84
Mahmoud Samir Fayed
?
Easy Button
Easy Button
Adam Dale
?
Android App Development - 07 Threading
Android App Development - 07 Threading
Diego Grancini
?
JS and patterns
JS and patterns
David Rodenas
?
VisualStudio2012-WhatsNew-TechEd_v3-9
VisualStudio2012-WhatsNew-TechEd_v3-9
SSW
?
¶ÅÔöÇ¿-¹ó±ô±ð³æ3×é¼þÉúÃüÖÜÆÚ
¶ÅÔöÇ¿-¹ó±ô±ð³æ3×é¼þÉúÃüÖÜÆÚ
ÔöÇ¿ ¶Å
?
Testing in android
Testing in android
jtrindade
?
ASP.NET MVC Internals
ASP.NET MVC Internals
Vitaly Baum
?
Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2
Fabio Collini
?
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWT
David Chandler
?
Reliability and Reslience
Reliability and Reslience
Donald Belcham
?
Testing with Containers
Testing with Containers
Romain Baugue
?
Android architecture component - FbCircleDev Yogyakarta Indonesia
Android architecture component - FbCircleDev Yogyakarta Indonesia
Pratama Nur Wijaya
?
The Ring programming language version 1.2 book - Part 28 of 84
The Ring programming language version 1.2 book - Part 28 of 84
Mahmoud Samir Fayed
?
Android App Development - 07 Threading
Android App Development - 07 Threading
Diego Grancini
?
VisualStudio2012-WhatsNew-TechEd_v3-9
VisualStudio2012-WhatsNew-TechEd_v3-9
SSW
?
¶ÅÔöÇ¿-¹ó±ô±ð³æ3×é¼þÉúÃüÖÜÆÚ
¶ÅÔöÇ¿-¹ó±ô±ð³æ3×é¼þÉúÃüÖÜÆÚ
ÔöÇ¿ ¶Å
?
Testing in android
Testing in android
jtrindade
?
ASP.NET MVC Internals
ASP.NET MVC Internals
Vitaly Baum
?
Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2
Fabio Collini
?
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWT
David Chandler
?
Reliability and Reslience
Reliability and Reslience
Donald Belcham
?
Testing with Containers
Testing with Containers
Romain Baugue
?
Android architecture component - FbCircleDev Yogyakarta Indonesia
Android architecture component - FbCircleDev Yogyakarta Indonesia
Pratama Nur Wijaya
?

More from Steve Loughran (20)

Hadoop Vectored IO
Hadoop Vectored IO
Steve Loughran
?
The age of rename() is over
The age of rename() is over
Steve Loughran
?
What does Rename Do: (detailed version)
What does Rename Do: (detailed version)
Steve Loughran
?
Put is the new rename: San Jose Summit Edition
Put is the new rename: San Jose Summit Edition
Steve Loughran
?
@Dissidentbot: dissent will be automated!
@Dissidentbot: dissent will be automated!
Steve Loughran
?
PUT is the new rename()
PUT is the new rename()
Steve Loughran
?
Extreme Programming Deployed
Extreme Programming Deployed
Steve Loughran
?
Testing
Testing
Steve Loughran
?
What does rename() do?
What does rename() do?
Steve Loughran
?
Dancing Elephants: Working with Object Storage in Apache Spark and Hive
Dancing Elephants: Working with Object Storage in Apache Spark and Hive
Steve Loughran
?
Apache Spark and Object Stores ¡ªfor London Spark User Group
Apache Spark and Object Stores ¡ªfor London Spark User Group
Steve Loughran
?
Spark Summit East 2017: Apache spark and object stores
Spark Summit East 2017: Apache spark and object stores
Steve Loughran
?
Hadoop, Hive, Spark and Object Stores
Hadoop, Hive, Spark and Object Stores
Steve Loughran
?
Apache Spark and Object Stores
Apache Spark and Object Stores
Steve Loughran
?
Household INFOSEC in a Post-Sony Era
Household INFOSEC in a Post-Sony Era
Steve Loughran
?
Hadoop and Kerberos: the Madness Beyond the Gate: January 2016 edition
Hadoop and Kerberos: the Madness Beyond the Gate: January 2016 edition
Steve Loughran
?
Hadoop and Kerberos: the Madness Beyond the Gate
Hadoop and Kerberos: the Madness Beyond the Gate
Steve Loughran
?
ºÝºÝߣr: Applications on YARN
ºÝºÝߣr: Applications on YARN
Steve Loughran
?
YARN Services
YARN Services
Steve Loughran
?
Datacentre stack
Datacentre stack
Steve Loughran
?
The age of rename() is over
The age of rename() is over
Steve Loughran
?
What does Rename Do: (detailed version)
What does Rename Do: (detailed version)
Steve Loughran
?
Put is the new rename: San Jose Summit Edition
Put is the new rename: San Jose Summit Edition
Steve Loughran
?
@Dissidentbot: dissent will be automated!
@Dissidentbot: dissent will be automated!
Steve Loughran
?
Extreme Programming Deployed
Extreme Programming Deployed
Steve Loughran
?
Dancing Elephants: Working with Object Storage in Apache Spark and Hive
Dancing Elephants: Working with Object Storage in Apache Spark and Hive
Steve Loughran
?
Apache Spark and Object Stores ¡ªfor London Spark User Group
Apache Spark and Object Stores ¡ªfor London Spark User Group
Steve Loughran
?
Spark Summit East 2017: Apache spark and object stores
Spark Summit East 2017: Apache spark and object stores
Steve Loughran
?
Hadoop, Hive, Spark and Object Stores
Hadoop, Hive, Spark and Object Stores
Steve Loughran
?
Apache Spark and Object Stores
Apache Spark and Object Stores
Steve Loughran
?
Household INFOSEC in a Post-Sony Era
Household INFOSEC in a Post-Sony Era
Steve Loughran
?
Hadoop and Kerberos: the Madness Beyond the Gate: January 2016 edition
Hadoop and Kerberos: the Madness Beyond the Gate: January 2016 edition
Steve Loughran
?
Hadoop and Kerberos: the Madness Beyond the Gate
Hadoop and Kerberos: the Madness Beyond the Gate
Steve Loughran
?
ºÝºÝߣr: Applications on YARN
ºÝºÝߣr: Applications on YARN
Steve Loughran
?
Ad

Recently uploaded (20)

CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
?
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
?
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
?
Heat Treatment Process Automation in India
Heat Treatment Process Automation in India
Reckers Mechatronics
?
Test Case Design Techniques ¨C Practical Examples & Best Practices in Software...
Test Case Design Techniques ¨C Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
?
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Philip Schwarz
?
Which Hiring Management Tools Offer the Best ROI?
Which Hiring Management Tools Offer the Best ROI?
HireME
?
Digital Transformation: Automating the Placement of Medical Interns
Digital Transformation: Automating the Placement of Medical Interns
Safe Software
?
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
?
Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
?
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
?
The Anti-Masterclass Live - Peak of Data & AI 2025
The Anti-Masterclass Live - Peak of Data & AI 2025
Safe Software
?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
?
Simplify Task, Team, and Project Management with Orangescrum Work
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
?
arctitecture application system design os dsa
arctitecture application system design os dsa
za241967
?
Zoneranker¡¯s Digital marketing solutions
Zoneranker¡¯s Digital marketing solutions
reenashriee
?
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
?
IObit Driver Booster Pro 12 Crack Latest Version Download
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
?
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
?
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
?
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
?
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
?
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
?
Heat Treatment Process Automation in India
Heat Treatment Process Automation in India
Reckers Mechatronics
?
Test Case Design Techniques ¨C Practical Examples & Best Practices in Software...
Test Case Design Techniques ¨C Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
?
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Philip Schwarz
?
Which Hiring Management Tools Offer the Best ROI?
Which Hiring Management Tools Offer the Best ROI?
HireME
?
Digital Transformation: Automating the Placement of Medical Interns
Digital Transformation: Automating the Placement of Medical Interns
Safe Software
?
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
?
Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
?
The Anti-Masterclass Live - Peak of Data & AI 2025
The Anti-Masterclass Live - Peak of Data & AI 2025
Safe Software
?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
?
Simplify Task, Team, and Project Management with Orangescrum Work
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
?
arctitecture application system design os dsa
arctitecture application system design os dsa
za241967
?
Zoneranker¡¯s Digital marketing solutions
Zoneranker¡¯s Digital marketing solutions
reenashriee
?
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
?
IObit Driver Booster Pro 12 Crack Latest Version Download
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
?
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
?
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
?
Ad

I hate mocking

  • 5. when(mockClient .initiateMultipartUpload(any(InitiateMultipartUploadRequest.class))) .thenAnswer(new Answer<InitiateMultipartUploadResult>() { @Override public InitiateMultipartUploadResult answer( InvocationOnMock invocation) throws Throwable { LOG.debug("initiateMultipartUpload for {}", mockClient); synchronized (lock) { if (results.requests.size() == errors.failOnInit) { if (errors.recover) errors.failOnInit(-1); throw new AmazonClientException("Fail on init " + results.requests.size()); } String uploadId = UUID.randomUUID().toString(); results.requests.put(uploadId, invocation.getArgumentAt( 0, InitiateMultipartUploadRequest.class)); results.uploads.add(uploadId); return newResult(results.requests.get(uploadId), uploadId); } } });
  • 6. ? Mock code reflects our assumptions about system behaviour ? Doesn't verify that the caller would work against real service ? Any change in real code breaks the tests: false positives ? Test failures often "fixed" by editing test/mock ... which could hide real problems Why bother? It's high-maintenance suffering
  • 8. Proposed ? Avoid mock tests ? Add functional tests against real infrastructure ? Embed fault injection ability into functional code ? Use for integration testing