SlideShare a Scribd company logo
Mockito vs JMockit,
battle of the mocking
frameworks
The art of pretending
2
In all it’s glory
• Has been around since 2008
• Is the industry standard ever since
• In 2013 more then 30.000 Github project
• More popular then Spring and Guava
• Most distinguishing feature
• Verify the behaviour of the SUT without
establishing expectations beforehand
3
Mockito in action
4
Mockito in action
5
Mockito in action
6
So for, so good
• Arrange, Act, Assert
• Mock any class, interface, method
• No need for introducing test interface
shims
• Declarative style for setting up behaviour
• Declarative style for verifying behaviour
• …
• In the happy flow
7
This gun’ be good
8
This gonna be good
• Mocking void methods
• Mocking finals
• Mocking statics
• Verifying constructors
9
This gonna be good
• Make a test shim
• Extend the class and scoop the methods
• Make an adapter or facade
• Why aren’t they using interfaces in the
first place
• The final keyword should be banned
• Let’s agree not to test this
• Ahh.. let’s use
PowerMockito!
10
JMockit
11
JMockit in action
12
JMockit in action
13
JMockit in action
14
JMockit in action
15
• Expectations are like Mockito.when(…)
• Verifications are like Mockito.verify(…)
JMockit in action
16
• Uniform notation for
• Primitives
• Complex objects
• Exceptions
• Custom Answers
JMockit in action
17
Annotations - With great power…
18
• @Injectable
• Single mock instance
• @Mocked
• Entire class mock (at bytecode level)
• @Capturing
• Any derived instance and subclass will be a class mock
• @Tested
• System under test
• Tries to satisfy Constructor, @Autowired, @Injectable
… comes great responsibility - Scoping
19
Legacy mock injection
20
Real world examples
21
java.lang.RuntimeException: Method getWindow in android.app.Activity not mocked. See
http://g.co/androidstudio/not-mocked for details.
at android.app.Activity.getWindow(Activity.java)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:117)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:456)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at ExampleActivity.onCreate(ExampleActivity.java:15)
at ExampleActivityTest.
shouldCommitFragment_whenOnCreateIsCalled(ExampleActivityTest.java:9)
Real world examples
22
akka.actor.ActorInitializationException: You cannot create an instance of
[com.cc.LoggingHandler] explicitly using the constructor (new). You have to use one of
the 'actorOf' factory methods to create a new actor. See the documentation.
at akka.actor.ActorInitializationException$.apply(Actor.scala:173)
at akka.actor.Actor$class.$init$(Actor.scala:436)
at akka.actor.UntypedActor.<init>(UntypedActor.scala:97)
at com.cc.LoggingHandler.<init>(LoggingHandler.java:14)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at …
Real world examples
23
24
JMockit
25
JMockit
JMockit’s Advantages
• Mockito’s distinguishing feature covered by
JMockit
• Verify the behaviour of the SUT without establishing expectations
beforehand
• No need for special test runners
• No limit on testing statics, finals,
constructors and whatnot
• No limitations/anomalies in your code due
to the test framework
26
JMockit’s Disadvantages
• Risk of introducing in your code
• Static methods
• Not using dependency injection
• Need to get accustomed to new mocking
framework
• Mockito’s error messages are more
explicit
• Mockito forces proper dependencies
27
Some figures
• Github grade and maven dependencies
• Mockito: 131.525
• JMockit: 3.058
• First mentioned - first release:
• Mockito: 2008 - 2008
• JMockit: 2006 - 2012
• Both under constant development
28
Read more
• Official pages:
• Mockito: http://mockito.org/
• JMockit: http://jmockit.org/
• My blog:
• www.endran.nl/blog
• Mockito vs JMockit, battle of the
mocking frameworks
• Death to statics
29
30
“I Don’t Always Test My Code. But When I Do, I Do It In
Production.”

More Related Content

What's hot

Android Navigation Component
Android Navigation ComponentAndroid Navigation Component
Android Navigation Component
Łukasz Ciupa
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
Hitesh-Java
 
Introduction To Angular's reactive forms
Introduction To Angular's reactive formsIntroduction To Angular's reactive forms
Introduction To Angular's reactive forms
Nir Kaufman
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
OOP java
OOP javaOOP java
OOP java
xball977
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
Rajiv Srivastava
 
Important React Hooks
Important React HooksImportant React Hooks
Important React Hooks
Knoldus Inc.
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
Sanjoy Kumar Roy
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
07.pallav
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examples
ecosio GmbH
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
Scott Leberknight
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
Anup Burange
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
Eyal Vardi
 
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
elliando dias
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
Atul Sehdev
 
Jdbc Ppt
Jdbc PptJdbc Ppt
15. DateTime API.ppt
15. DateTime API.ppt15. DateTime API.ppt
15. DateTime API.ppt
VISHNUSHANKARSINGH3
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module Patterns
Nicholas Jansma
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Hitesh Kumar
 

What's hot (20)

Android Navigation Component
Android Navigation ComponentAndroid Navigation Component
Android Navigation Component
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Introduction To Angular's reactive forms
Introduction To Angular's reactive formsIntroduction To Angular's reactive forms
Introduction To Angular's reactive forms
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
OOP java
OOP javaOOP java
OOP java
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 
Important React Hooks
Important React HooksImportant React Hooks
Important React Hooks
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examples
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Java awt
Java awtJava awt
Java awt
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
15. DateTime API.ppt
15. DateTime API.ppt15. DateTime API.ppt
15. DateTime API.ppt
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module Patterns
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 

Viewers also liked

Android Automation Using Robotium
Android Automation Using RobotiumAndroid Automation Using Robotium
Android Automation Using Robotium
Mindfire Solutions
 
Mocking in Python
Mocking in PythonMocking in Python
Mocking in Python
Excella
 
Testing Angular 2 Applications - Rich Web 2016
Testing Angular 2 Applications - Rich Web 2016Testing Angular 2 Applications - Rich Web 2016
Testing Angular 2 Applications - Rich Web 2016
Matt Raible
 
Making a Mock by Kelsey Shannahan
Making a Mock by Kelsey ShannahanMaking a Mock by Kelsey Shannahan
Making a Mock by Kelsey Shannahan
QA or the Highway
 
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
Matt Raible
 
JMockit
JMockitJMockit
JMockit
Angad Rajput
 
Linux principles and philosophy
Linux principles and philosophyLinux principles and philosophy
Linux principles and philosophy
Fa6ma_
 
Unix philosophy and principles
Unix philosophy and principlesUnix philosophy and principles
Unix philosophy and principles
maryamalmarrii
 
Linux principles and philosophy
Linux principles and philosophyLinux principles and philosophy
Linux principles and philosophy
aliabintouq
 
Mobile Knife Fighting at JSConf US
Mobile Knife Fighting at JSConf US Mobile Knife Fighting at JSConf US
Mobile Knife Fighting at JSConf US
Brian LeRoux
 
Eduards Sizovs - Micro Service Architecture
Eduards Sizovs - Micro Service Architecture Eduards Sizovs - Micro Service Architecture
Eduards Sizovs - Micro Service Architecture
DevConFu
 
Bringing the Unix Philosophy to Big Data
Bringing the Unix Philosophy to Big DataBringing the Unix Philosophy to Big Data
Bringing the Unix Philosophy to Big Data
bcantrill
 
Mocking Test - QA Ninja Conf 2016
Mocking Test - QA Ninja Conf 2016Mocking Test - QA Ninja Conf 2016
Mocking Test - QA Ninja Conf 2016
Renato Groff
 
Unix Philosophy
Unix PhilosophyUnix Philosophy
Unix Philosophy
Lissa Potter
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
Joe Wilson
 
Writing Well-Behaved Unix Utilities
Writing Well-Behaved Unix UtilitiesWriting Well-Behaved Unix Utilities
Writing Well-Behaved Unix Utilities
Rob Miller
 
Circuit breakers for Java: Failsafe, Javaslang-Circuitbreaker, Hystrix and Ve...
Circuit breakers for Java: Failsafe, Javaslang-Circuitbreaker, Hystrix and Ve...Circuit breakers for Java: Failsafe, Javaslang-Circuitbreaker, Hystrix and Ve...
Circuit breakers for Java: Failsafe, Javaslang-Circuitbreaker, Hystrix and Ve...
Micha Kops
 
Easymock Tutorial
Easymock TutorialEasymock Tutorial
Easymock Tutorial
Sbin m
 
To Microservices and Beyond
To Microservices and BeyondTo Microservices and Beyond
To Microservices and Beyond
Matt Stine
 
Using Hystrix to Build Resilient Distributed Systems
Using Hystrix to Build Resilient Distributed SystemsUsing Hystrix to Build Resilient Distributed Systems
Using Hystrix to Build Resilient Distributed Systems
Matt Jacobs
 

Viewers also liked (20)

Android Automation Using Robotium
Android Automation Using RobotiumAndroid Automation Using Robotium
Android Automation Using Robotium
 
Mocking in Python
Mocking in PythonMocking in Python
Mocking in Python
 
Testing Angular 2 Applications - Rich Web 2016
Testing Angular 2 Applications - Rich Web 2016Testing Angular 2 Applications - Rich Web 2016
Testing Angular 2 Applications - Rich Web 2016
 
Making a Mock by Kelsey Shannahan
Making a Mock by Kelsey ShannahanMaking a Mock by Kelsey Shannahan
Making a Mock by Kelsey Shannahan
 
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
 
JMockit
JMockitJMockit
JMockit
 
Linux principles and philosophy
Linux principles and philosophyLinux principles and philosophy
Linux principles and philosophy
 
Unix philosophy and principles
Unix philosophy and principlesUnix philosophy and principles
Unix philosophy and principles
 
Linux principles and philosophy
Linux principles and philosophyLinux principles and philosophy
Linux principles and philosophy
 
Mobile Knife Fighting at JSConf US
Mobile Knife Fighting at JSConf US Mobile Knife Fighting at JSConf US
Mobile Knife Fighting at JSConf US
 
Eduards Sizovs - Micro Service Architecture
Eduards Sizovs - Micro Service Architecture Eduards Sizovs - Micro Service Architecture
Eduards Sizovs - Micro Service Architecture
 
Bringing the Unix Philosophy to Big Data
Bringing the Unix Philosophy to Big DataBringing the Unix Philosophy to Big Data
Bringing the Unix Philosophy to Big Data
 
Mocking Test - QA Ninja Conf 2016
Mocking Test - QA Ninja Conf 2016Mocking Test - QA Ninja Conf 2016
Mocking Test - QA Ninja Conf 2016
 
Unix Philosophy
Unix PhilosophyUnix Philosophy
Unix Philosophy
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Writing Well-Behaved Unix Utilities
Writing Well-Behaved Unix UtilitiesWriting Well-Behaved Unix Utilities
Writing Well-Behaved Unix Utilities
 
Circuit breakers for Java: Failsafe, Javaslang-Circuitbreaker, Hystrix and Ve...
Circuit breakers for Java: Failsafe, Javaslang-Circuitbreaker, Hystrix and Ve...Circuit breakers for Java: Failsafe, Javaslang-Circuitbreaker, Hystrix and Ve...
Circuit breakers for Java: Failsafe, Javaslang-Circuitbreaker, Hystrix and Ve...
 
Easymock Tutorial
Easymock TutorialEasymock Tutorial
Easymock Tutorial
 
To Microservices and Beyond
To Microservices and BeyondTo Microservices and Beyond
To Microservices and Beyond
 
Using Hystrix to Build Resilient Distributed Systems
Using Hystrix to Build Resilient Distributed SystemsUsing Hystrix to Build Resilient Distributed Systems
Using Hystrix to Build Resilient Distributed Systems
 

Similar to Mockito vs JMockit, battle of the mocking frameworks

Junit, mockito, etc
Junit, mockito, etcJunit, mockito, etc
Junit, mockito, etc
Yaron Karni
 
Dependency Injection in .NET applications
Dependency Injection in .NET applicationsDependency Injection in .NET applications
Dependency Injection in .NET applications
Babak Naffas
 
Unit Test Android Without Going Bald
Unit Test Android Without Going BaldUnit Test Android Without Going Bald
Unit Test Android Without Going Bald
David Carver
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability
drewz lin
 
GWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 PanicGWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 Panic
Cristiano Costantini
 
Droidcon Spain 2016 - The Pragmatic Android Programmer: from hype to reality
 Droidcon Spain 2016 - The Pragmatic Android Programmer: from hype to reality Droidcon Spain 2016 - The Pragmatic Android Programmer: from hype to reality
Droidcon Spain 2016 - The Pragmatic Android Programmer: from hype to reality
Daniel Gallego Vico
 
Implementing Quality on a Java Project
Implementing Quality on a Java ProjectImplementing Quality on a Java Project
Implementing Quality on a Java Project
Vincent Massol
 
Unit testing basic
Unit testing basicUnit testing basic
Unit testing basic
Yuri Anischenko
 
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous DeliveryBridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Delivery
masoodjan
 
Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018
Hazem Saleh
 
Visual Automation Framework via Screenshot Comparison
Visual Automation Framework via Screenshot ComparisonVisual Automation Framework via Screenshot Comparison
Visual Automation Framework via Screenshot Comparison
Mek Srunyu Stittri
 
Introduction to Robotium
Introduction to RobotiumIntroduction to Robotium
Introduction to Robotium
alii abbb
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven Development
Dhaval Shah
 
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
Applitools
 
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Christian Catalan
 
Testing w-mocks
Testing w-mocksTesting w-mocks
Testing w-mocks
Macon Pegram
 
Object-oriented design principles
Object-oriented design principlesObject-oriented design principles
Object-oriented design principles
Xiaoyan Chen
 
Introduction to Protractor - Habilelabs
Introduction to Protractor - HabilelabsIntroduction to Protractor - Habilelabs
Introduction to Protractor - Habilelabs
Habilelabs
 
Mock with Mockito
Mock with MockitoMock with Mockito
Mock with Mockito
Camilo Lopes
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 

Similar to Mockito vs JMockit, battle of the mocking frameworks (20)

Junit, mockito, etc
Junit, mockito, etcJunit, mockito, etc
Junit, mockito, etc
 
Dependency Injection in .NET applications
Dependency Injection in .NET applicationsDependency Injection in .NET applications
Dependency Injection in .NET applications
 
Unit Test Android Without Going Bald
Unit Test Android Without Going BaldUnit Test Android Without Going Bald
Unit Test Android Without Going Bald
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability
 
GWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 PanicGWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 Panic
 
Droidcon Spain 2016 - The Pragmatic Android Programmer: from hype to reality
 Droidcon Spain 2016 - The Pragmatic Android Programmer: from hype to reality Droidcon Spain 2016 - The Pragmatic Android Programmer: from hype to reality
Droidcon Spain 2016 - The Pragmatic Android Programmer: from hype to reality
 
Implementing Quality on a Java Project
Implementing Quality on a Java ProjectImplementing Quality on a Java Project
Implementing Quality on a Java Project
 
Unit testing basic
Unit testing basicUnit testing basic
Unit testing basic
 
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous DeliveryBridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Delivery
 
Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018
 
Visual Automation Framework via Screenshot Comparison
Visual Automation Framework via Screenshot ComparisonVisual Automation Framework via Screenshot Comparison
Visual Automation Framework via Screenshot Comparison
 
Introduction to Robotium
Introduction to RobotiumIntroduction to Robotium
Introduction to Robotium
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven Development
 
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
 
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
 
Testing w-mocks
Testing w-mocksTesting w-mocks
Testing w-mocks
 
Object-oriented design principles
Object-oriented design principlesObject-oriented design principles
Object-oriented design principles
 
Introduction to Protractor - Habilelabs
Introduction to Protractor - HabilelabsIntroduction to Protractor - Habilelabs
Introduction to Protractor - Habilelabs
 
Mock with Mockito
Mock with MockitoMock with Mockito
Mock with Mockito
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 

Recently uploaded

SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 

Recently uploaded (20)

SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 

Mockito vs JMockit, battle of the mocking frameworks

  • 1. Mockito vs JMockit, battle of the mocking frameworks The art of pretending
  • 2. 2
  • 3. In all it’s glory • Has been around since 2008 • Is the industry standard ever since • In 2013 more then 30.000 Github project • More popular then Spring and Guava • Most distinguishing feature • Verify the behaviour of the SUT without establishing expectations beforehand 3
  • 7. So for, so good • Arrange, Act, Assert • Mock any class, interface, method • No need for introducing test interface shims • Declarative style for setting up behaviour • Declarative style for verifying behaviour • … • In the happy flow 7
  • 8. This gun’ be good 8
  • 9. This gonna be good • Mocking void methods • Mocking finals • Mocking statics • Verifying constructors 9
  • 10. This gonna be good • Make a test shim • Extend the class and scoop the methods • Make an adapter or facade • Why aren’t they using interfaces in the first place • The final keyword should be banned • Let’s agree not to test this • Ahh.. let’s use PowerMockito! 10
  • 15. JMockit in action 15 • Expectations are like Mockito.when(…) • Verifications are like Mockito.verify(…)
  • 16. JMockit in action 16 • Uniform notation for • Primitives • Complex objects • Exceptions • Custom Answers
  • 18. Annotations - With great power… 18 • @Injectable • Single mock instance • @Mocked • Entire class mock (at bytecode level) • @Capturing • Any derived instance and subclass will be a class mock • @Tested • System under test • Tries to satisfy Constructor, @Autowired, @Injectable
  • 19. … comes great responsibility - Scoping 19
  • 21. Real world examples 21 java.lang.RuntimeException: Method getWindow in android.app.Activity not mocked. See http://g.co/androidstudio/not-mocked for details. at android.app.Activity.getWindow(Activity.java) at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:117) at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:456) at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59) at ExampleActivity.onCreate(ExampleActivity.java:15) at ExampleActivityTest. shouldCommitFragment_whenOnCreateIsCalled(ExampleActivityTest.java:9)
  • 22. Real world examples 22 akka.actor.ActorInitializationException: You cannot create an instance of [com.cc.LoggingHandler] explicitly using the constructor (new). You have to use one of the 'actorOf' factory methods to create a new actor. See the documentation. at akka.actor.ActorInitializationException$.apply(Actor.scala:173) at akka.actor.Actor$class.$init$(Actor.scala:436) at akka.actor.UntypedActor.<init>(UntypedActor.scala:97) at com.cc.LoggingHandler.<init>(LoggingHandler.java:14) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at …
  • 26. JMockit’s Advantages • Mockito’s distinguishing feature covered by JMockit • Verify the behaviour of the SUT without establishing expectations beforehand • No need for special test runners • No limit on testing statics, finals, constructors and whatnot • No limitations/anomalies in your code due to the test framework 26
  • 27. JMockit’s Disadvantages • Risk of introducing in your code • Static methods • Not using dependency injection • Need to get accustomed to new mocking framework • Mockito’s error messages are more explicit • Mockito forces proper dependencies 27
  • 28. Some figures • Github grade and maven dependencies • Mockito: 131.525 • JMockit: 3.058 • First mentioned - first release: • Mockito: 2008 - 2008 • JMockit: 2006 - 2012 • Both under constant development 28
  • 29. Read more • Official pages: • Mockito: http://mockito.org/ • JMockit: http://jmockit.org/ • My blog: • www.endran.nl/blog • Mockito vs JMockit, battle of the mocking frameworks • Death to statics 29
  • 30. 30 “I Don’t Always Test My Code. But When I Do, I Do It In Production.”

Editor's Notes

  1. Final class wont work Final method wont work Static method cannot be mocked Thread.sleep will be executed every time
  2. Hint about the annotaions, details in next slides Expectations is like Mockito when, not necessary for verifications
  3. Times 1 is optional Thread sleep can just be mocked
  4. minTimes is optional. Set to 0 to be exactly like Mockito when. Expectations need to be met. Not meeting expectations will fail your test. GoogleMock users can still do their expectations beforehand, Mockito user can still do verification afterwards.
  5. Any mated with matching signature
  6. A captor is just a list with the type you want to capture. Assertions can be done in the Verifications, or outside of them. Dealers choice.
  7. This legacy code doesn’t have Dependency injection Just mock the constructor
  8. Akka provides a mechanism to create test actors and whatnot, but it also does some lifecycle methods. This unit test only tests our code, and ignores framework limitations
  9. Akka provides a mechanism to create test actors and whatnot, but it also does some lifecycle methods. This unit test only tests our code, and ignores framework limitations
  10. This is the same test as the @Capture before. Without @Capture we need to setup the entire test suite ourselves Before setup the mocks are created, after setup @Tested is created. Static constructor dependencies are resolved after the setup, before the test. Since we do not know exactly which concrete class Logger is, @Captor will mock any Logger.