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

More Related Content

PDF
Python: the coolest is yet to come
PPT
Unit testing with mock libs
PDF
Implicit and Explicit waits in Selenium WebDriwer, how to.
PDF
WebDriver Waits
PDF
Automation puzzlers
PDF
Martin Anderson - threads v actors
PDF
Developed your first Xamarin.Forms Application
PDF
Testing with Kotlin
Python: the coolest is yet to come
Unit testing with mock libs
Implicit and Explicit waits in Selenium WebDriwer, how to.
WebDriver Waits
Automation puzzlers
Martin Anderson - threads v actors
Developed your first Xamarin.Forms Application
Testing with Kotlin

What's hot (13)

PDF
The Ring programming language version 1.2 book - Part 28 of 84
RTF
Easy Button
ODP
Android App Development - 07 Threading
PDF
JS and patterns
PPTX
VisualStudio2012-WhatsNew-TechEd_v3-9
 
PDF
杜增强-Flex3组件生命周期
PDF
Testing in android
PDF
ASP.NET MVC Internals
PDF
Intro to Retrofit 2 and RxJava2
PDF
Easy REST APIs with Jersey and RestyGWT
PPTX
Reliability and Reslience
PDF
Testing with Containers
PDF
Android architecture component - FbCircleDev Yogyakarta Indonesia
The Ring programming language version 1.2 book - Part 28 of 84
Easy Button
Android App Development - 07 Threading
JS and patterns
VisualStudio2012-WhatsNew-TechEd_v3-9
 
杜增强-Flex3组件生命周期
Testing in android
ASP.NET MVC Internals
Intro to Retrofit 2 and RxJava2
Easy REST APIs with Jersey and RestyGWT
Reliability and Reslience
Testing with Containers
Android architecture component - FbCircleDev Yogyakarta Indonesia
Ad

Similar to I hate mocking (20)

ODP
Unit testing with Easymock
PDF
Creating a Facebook Clone - Part XLVI - Transcript.pdf
PDF
Android testing
PDF
Nevyn — Promise, It's Async! Swift Language User Group Lightning Talk 2015-09-24
PPTX
Dat testing - An introduction to Java and Android Testing
PPSX
Java.lang.object
PDF
Sane Async Patterns
PDF
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
PPT
Orsiso
PPT
2012 JDays Bad Tests Good Tests
PPTX
The secret unit testing tools no one ever told you about
PPTX
Mockito intro
PPTX
Unit testing CourseSites Apache Filter
PDF
Creating a Facebook Clone - Part XLVI.pdf
PPTX
Deep dive into new ASP.NET MVC 4 Features
KEY
Lazy Loading Because I'm Lazy
PPTX
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
PDF
Understanding JavaScript Testing
PPTX
Junit 5 - Maior e melhor
PPT
比XML更好用的Java Annotation
Unit testing with Easymock
Creating a Facebook Clone - Part XLVI - Transcript.pdf
Android testing
Nevyn — Promise, It's Async! Swift Language User Group Lightning Talk 2015-09-24
Dat testing - An introduction to Java and Android Testing
Java.lang.object
Sane Async Patterns
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
Orsiso
2012 JDays Bad Tests Good Tests
The secret unit testing tools no one ever told you about
Mockito intro
Unit testing CourseSites Apache Filter
Creating a Facebook Clone - Part XLVI.pdf
Deep dive into new ASP.NET MVC 4 Features
Lazy Loading Because I'm Lazy
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Understanding JavaScript Testing
Junit 5 - Maior e melhor
比XML更好用的Java Annotation
Ad

More from Steve Loughran (20)

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

Recently uploaded (20)

PDF
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PPTX
Computer Software - Technology and Livelihood Education
PDF
Autodesk AutoCAD Crack Free Download 2025
PPTX
GSA Content Generator Crack (2025 Latest)
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
Types of Token_ From Utility to Security.pdf
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Microsoft Office 365 Crack Download Free
DOCX
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PPTX
Computer Software and OS of computer science of grade 11.pptx
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PPTX
CNN LeNet5 Architecture: Neural Networks
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
PDF
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
PPTX
Monitoring Stack: Grafana, Loki & Promtail
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
Topaz Photo AI Crack New Download (Latest 2025)
Computer Software - Technology and Livelihood Education
Autodesk AutoCAD Crack Free Download 2025
GSA Content Generator Crack (2025 Latest)
iTop VPN Crack Latest Version Full Key 2025
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Types of Token_ From Utility to Security.pdf
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Microsoft Office 365 Crack Download Free
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
DNT Brochure 2025 – ISV Solutions @ D365
Computer Software and OS of computer science of grade 11.pptx
How to Use SharePoint as an ISO-Compliant Document Management System
Wondershare Recoverit Full Crack New Version (Latest 2025)
CNN LeNet5 Architecture: Neural Networks
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
Monitoring Stack: Grafana, Loki & Promtail

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