SlideShare a Scribd company logo
EasyMock
Mock object framework for java
development
By Franck Benault
Created 16/11/2014
Last updated 11/11/2014
EasyMock plan
Unit test in java
● Main framework : Junit and TestNG
● Database management (fill or check content)
– DbUnit
– DbSetup
● Mock object frameworks
– EasyMock
– Mockito
Goal of EasyMock
● On the web site of EasyMock (www.easymock.org)
– Great (unit) testing includes isolation
– Isolation involves mock objects
– EasyMock makes mocking easier
What is a mock
Mock objects
● Unit tests are white box tests
– The developers is allowed to look at the code
● Mock objects replaces the objects linked to the object we
want to test
● It becomes possible to test more path (exceptions, errors)
● We have to change a little the implementation to make the
mocking easier
Mock objects
● Unit tests are white box tests
– The developers is allowed to look at the code
● Mock objects replaces the objects linked to the object we
want to test
● It becomes possible to test more path (exceptions, errors)
● We have to change a little the implementation to make the
mocking easier
Features of Mock frameworks
● Main features
– Value returning for a stubbed method
– Exception throwing for a stubbed method
– Invocation check method
– Method arguments check
– Invocation order for one mock check
● Advance features
– Stubbing of equals() and hashCode() methods
– ...
Features of Mock frameworks
● Main features
– Value returning for a stubbed method
– Exception throwing for a stubbed method
– Invocation check method
– Method arguments check
– Invocation order for one mock check
● Advance features
– Stubbing of equals() and hashCode() methods
– ...
Main mock frameworks (in java)
● Open projects well know
– EasyMock
– Jmockit
– Mockito
– Jmock
EasyMock live cycle of mock
objects
● Create a mock
● Set up your expectation
● Set the mock to replay mode
– Call your code under test
● Verify that your expectation have been set
EasyMock create mock (strict of
nice)
● Create a mock
– CreateNiceMock()
● Unexpected returns an empty value (0 or null)
– CreateMock()
● The order of the call is not checked
– CreateStrictMock()
● The order of the call is checked
EasyMock expection/replay/verify
EntityManager emMock =
EasyMock.createNiceMock(EntityManager.class);
EntityTransaction entityTransactionMock =
EasyMock.createNiceMock(EntityTransaction.class);
EasyMock.expect(emMock.getTransaction()).andReturn(entityT
ransactionMock).times(2);
EasyMock.replay(entityTransactionMock);
EasyMock.verify(entityTransactionMock);
EasyMock How to inject the mock
StudentManager StudentQuery
EasyMock How to inject the mock
@RunWith(EasyMockRunner.class)
public class StudentManagerMockTest {
@TestSubject //where to inject mocks
private static StudentManager studentManager;
@Mock(type = MockType.NICE) //mock to inject
private StudentQuery studentQueryMock =
EasyMock.createNiceMock(StudentQuery.class);
.../...

More Related Content

Similar to Easymock

CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
Ortus Solutions, Corp
 
EasyMock for Java
EasyMock for JavaEasyMock for Java
EasyMock for Java
Deepak Singhvi
 
Junit, mockito, etc
Junit, mockito, etcJunit, mockito, etc
Junit, mockito, etc
Yaron Karni
 
Bytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyBytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte Buddy
Koichi Sakata
 
Mock your way with Mockito
Mock your way with MockitoMock your way with Mockito
Mock your way with Mockito
Vitaly Polonetsky
 
Angular testing
Angular testingAngular testing
Angular testing
Yu Jin
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHPMarcos Quesada
 
Devday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvuDevday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvu
Phat VU
 
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
DevDay.org
 
Codemotion 2015 spock_workshop
Codemotion 2015 spock_workshopCodemotion 2015 spock_workshop
Codemotion 2015 spock_workshop
Fernando Redondo Ramírez
 
Greach 2015 Spock workshop
Greach 2015 Spock workshopGreach 2015 Spock workshop
Greach 2015 Spock workshop
Fernando Redondo Ramírez
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
Rody Middelkoop
 
Spring IO 2015 Spock Workshop
Spring IO 2015 Spock WorkshopSpring IO 2015 Spock Workshop
Spring IO 2015 Spock Workshop
Fernando Redondo Ramírez
 
Just Mock It - Mocks and Stubs
Just Mock It - Mocks and StubsJust Mock It - Mocks and Stubs
Just Mock It - Mocks and Stubs
Gavin Pickin
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
Eugenio Lentini
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
Unit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaUnit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - Kenya
Erick M'bwana
 

Similar to Easymock (20)

CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
EasyMock for Java
EasyMock for JavaEasyMock for Java
EasyMock for Java
 
Junit, mockito, etc
Junit, mockito, etcJunit, mockito, etc
Junit, mockito, etc
 
Bytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyBytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte Buddy
 
Mock your way with Mockito
Mock your way with MockitoMock your way with Mockito
Mock your way with Mockito
 
Angular testing
Angular testingAngular testing
Angular testing
 
Mockito
MockitoMockito
Mockito
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHP
 
Spock pres
Spock presSpock pres
Spock pres
 
Devday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvuDevday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvu
 
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
 
Codemotion 2015 spock_workshop
Codemotion 2015 spock_workshopCodemotion 2015 spock_workshop
Codemotion 2015 spock_workshop
 
Greach 2015 Spock workshop
Greach 2015 Spock workshopGreach 2015 Spock workshop
Greach 2015 Spock workshop
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 
Spring IO 2015 Spock Workshop
Spring IO 2015 Spock WorkshopSpring IO 2015 Spock Workshop
Spring IO 2015 Spock Workshop
 
Just Mock It - Mocks and Stubs
Just Mock It - Mocks and StubsJust Mock It - Mocks and Stubs
Just Mock It - Mocks and Stubs
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
 
Unit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaUnit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - Kenya
 
Cnc scala-presentation
Cnc scala-presentationCnc scala-presentation
Cnc scala-presentation
 

More from fbenault

Bdd java
Bdd javaBdd java
Bdd java
fbenault
 
Property based-testing
Property based-testingProperty based-testing
Property based-testing
fbenault
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
fbenault
 
Test ng
Test ngTest ng
Test ng
fbenault
 
Assertj-DB
Assertj-DBAssertj-DB
Assertj-DB
fbenault
 
Introduction to the language R
Introduction to the language RIntroduction to the language R
Introduction to the language R
fbenault
 
Assertj-core
Assertj-coreAssertj-core
Assertj-corefbenault
 
System rules
System rulesSystem rules
System rules
fbenault
 
Db in-memory
Db in-memoryDb in-memory
Db in-memory
fbenault
 

More from fbenault (13)

Bdd java
Bdd javaBdd java
Bdd java
 
Property based-testing
Property based-testingProperty based-testing
Property based-testing
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Test ng
Test ngTest ng
Test ng
 
Assertj-DB
Assertj-DBAssertj-DB
Assertj-DB
 
Introduction to the language R
Introduction to the language RIntroduction to the language R
Introduction to the language R
 
Assertj-core
Assertj-coreAssertj-core
Assertj-core
 
Junit
JunitJunit
Junit
 
System rules
System rulesSystem rules
System rules
 
Db in-memory
Db in-memoryDb in-memory
Db in-memory
 
DbSetup
DbSetupDbSetup
DbSetup
 
Guava
GuavaGuava
Guava
 
Java8
Java8Java8
Java8
 

Recently uploaded

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 

Recently uploaded (20)

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 

Easymock

  • 1. EasyMock Mock object framework for java development By Franck Benault Created 16/11/2014 Last updated 11/11/2014
  • 3. Unit test in java ● Main framework : Junit and TestNG ● Database management (fill or check content) – DbUnit – DbSetup ● Mock object frameworks – EasyMock – Mockito
  • 4. Goal of EasyMock ● On the web site of EasyMock (www.easymock.org) – Great (unit) testing includes isolation – Isolation involves mock objects – EasyMock makes mocking easier
  • 5. What is a mock
  • 6. Mock objects ● Unit tests are white box tests – The developers is allowed to look at the code ● Mock objects replaces the objects linked to the object we want to test ● It becomes possible to test more path (exceptions, errors) ● We have to change a little the implementation to make the mocking easier
  • 7. Mock objects ● Unit tests are white box tests – The developers is allowed to look at the code ● Mock objects replaces the objects linked to the object we want to test ● It becomes possible to test more path (exceptions, errors) ● We have to change a little the implementation to make the mocking easier
  • 8. Features of Mock frameworks ● Main features – Value returning for a stubbed method – Exception throwing for a stubbed method – Invocation check method – Method arguments check – Invocation order for one mock check ● Advance features – Stubbing of equals() and hashCode() methods – ...
  • 9. Features of Mock frameworks ● Main features – Value returning for a stubbed method – Exception throwing for a stubbed method – Invocation check method – Method arguments check – Invocation order for one mock check ● Advance features – Stubbing of equals() and hashCode() methods – ...
  • 10. Main mock frameworks (in java) ● Open projects well know – EasyMock – Jmockit – Mockito – Jmock
  • 11. EasyMock live cycle of mock objects ● Create a mock ● Set up your expectation ● Set the mock to replay mode – Call your code under test ● Verify that your expectation have been set
  • 12. EasyMock create mock (strict of nice) ● Create a mock – CreateNiceMock() ● Unexpected returns an empty value (0 or null) – CreateMock() ● The order of the call is not checked – CreateStrictMock() ● The order of the call is checked
  • 13. EasyMock expection/replay/verify EntityManager emMock = EasyMock.createNiceMock(EntityManager.class); EntityTransaction entityTransactionMock = EasyMock.createNiceMock(EntityTransaction.class); EasyMock.expect(emMock.getTransaction()).andReturn(entityT ransactionMock).times(2); EasyMock.replay(entityTransactionMock); EasyMock.verify(entityTransactionMock);
  • 14. EasyMock How to inject the mock StudentManager StudentQuery
  • 15. EasyMock How to inject the mock @RunWith(EasyMockRunner.class) public class StudentManagerMockTest { @TestSubject //where to inject mocks private static StudentManager studentManager; @Mock(type = MockType.NICE) //mock to inject private StudentQuery studentQueryMock = EasyMock.createNiceMock(StudentQuery.class); .../...