Your SlideShare is downloading. ×
0
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Easymock 101
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Easymock 101

3,827

Published on

A quick review of the EasyMock mocking (testing) framework and how it can make your testing more productive and less tightly coupled by Matthew McCullough.

A quick review of the EasyMock mocking (testing) framework and how it can make your testing more productive and less tightly coupled by Matthew McCullough.

Published in: Education
2 Comments
3 Likes
Statistics
Notes
No Downloads
Views
Total Views
3,827
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
141
Comments
2
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  1. EasyMock 101 A 30 Minute Review by Matthew McCullough
  2. ❶ What Is Mocking?
  3. Are You Mocking Me? • A fake object • Allows for more modular testing • Records and verifies expectations of calls
  4. ❷ Creating A Mock
  5. IEnumeration<Short> iEnumIntfMock = EasyMock.createMock(EnumeratedAttribute.class);
  6. ❸ Expectations
  7. Expecting A Lot • Expect method is called on mock • Expect sequence of method calls on mock (call createStrictMock()) • Expect parameters to methods calls on mock
  8. Expect A Call EasyMock.expect(iEnumIntfMock.getNumberOfRows() );
  9. Expect A Return EasyMock.expect(iEnumIntfMock.getNumberOfRows() ).andReturn(5);
  10. ❹ Replaying
  11. Replay • Prime the pump to walk through expected call sequence • Provide return values in same sequence • Listen to usage of call parameters
  12. Replay Kickoff EasyMock.replay(iEnumIntfMock);
  13. ❺ Using The ClassUnderTest
  14. Testing • Call all functions as you normally would • Pass in mock where injectable • Consider how mock can be passed into internal references
  15. Testing int numOfRows = iEnumIntfMock.getNumberOfRows(); Assert.assertTrue(quot;Number of rows does not matchquot;, numOfRows > 0);
  16. ❻ Verifying
  17. • Called after all operations with the mock are done • Compares the usage to the recording
  18. Verifying EasyMock.verify(iEnumIntfMock);
  19. ❼ Resources
  20. Resources • EasyMock.org • Groovy Mocking http://docs.codehaus.org/display/GROOVY/Groovy+Mocks

×