Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
© Henri Tremblay 2015
Henri Tremblay
Senior Software Engineer
Terracotta, a Software AG company
Do you know your mocks?
@h...
2
Authors:
Tim Mackinnon, Steve Freeman, Philip Craig
https://www2.ccs.neu.edu/research/demeter/related-
work/extreme-prog...
3
4
Henri Tremblay
• More or less made possible class mocking and proxying
• Coined the term “partial mocking”
5
Author:
Robert C. Martin
https://8thlight.com/blog/uncle-
bob/2014/05/14/TheLittleMocker.html
Uncle Bob mock classificat...
6
7
A class that you pass to something else when
you don't care how it's used.
Dummy
8
A class that returns a valid answer but always
the same one.
Stub
9
You use a spy when you want to be sure that
the authorize method was called by the system.
Spy
10
A true mock is a mock that knows how to verify
itself.
True Mock
11
A Fake has business behavior. You can drive a
fake to behave in different ways by giving it
different data.
Fake
12
Conclusion: KISS
13
Testing advices
14
Modify to test
15
Provide a testing
framework
16
Use as less
mocks as possible
17
Explain and
document your
tests
18
Refactor your
tests
19
Questions? http://montreal-jug.org
?
http://easymock.org
http://objenesis.org
http:/ehcache.org
Henri Tremblay
http://b...
Upcoming SlideShare
Loading in …5
×

Do you know your mock? - Madras JUG 20171028

85 views

Published on

An important pillar of unit tests is the Mock Object, also known as Test Doubles. They come in many types and flavours. Together, we will name them and demonstrate them using EasyMock and Mockito.

Source code: https://github.com/henri-tremblay/mocks

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Do you know your mock? - Madras JUG 20171028

  1. 1. © Henri Tremblay 2015 Henri Tremblay Senior Software Engineer Terracotta, a Software AG company Do you know your mocks? @henri_tremblay
  2. 2. 2 Authors: Tim Mackinnon, Steve Freeman, Philip Craig https://www2.ccs.neu.edu/research/demeter/related- work/extreme-programming/MockObjectsFinal.PDF Original Mock Object paper (2000)
  3. 3. 3
  4. 4. 4 Henri Tremblay • More or less made possible class mocking and proxying • Coined the term “partial mocking”
  5. 5. 5 Author: Robert C. Martin https://8thlight.com/blog/uncle- bob/2014/05/14/TheLittleMocker.html Uncle Bob mock classification (2014)
  6. 6. 6
  7. 7. 7 A class that you pass to something else when you don't care how it's used. Dummy
  8. 8. 8 A class that returns a valid answer but always the same one. Stub
  9. 9. 9 You use a spy when you want to be sure that the authorize method was called by the system. Spy
  10. 10. 10 A true mock is a mock that knows how to verify itself. True Mock
  11. 11. 11 A Fake has business behavior. You can drive a fake to behave in different ways by giving it different data. Fake
  12. 12. 12 Conclusion: KISS
  13. 13. 13 Testing advices
  14. 14. 14 Modify to test
  15. 15. 15 Provide a testing framework
  16. 16. 16 Use as less mocks as possible
  17. 17. 17 Explain and document your tests
  18. 18. 18 Refactor your tests
  19. 19. 19 Questions? http://montreal-jug.org ? http://easymock.org http://objenesis.org http:/ehcache.org Henri Tremblay http://blog.tremblay.pro @henri_tremblay

×