© Henri Tremblay 2015
Henri Tremblay
Senior Software Engineer
Terracotta, a Software AG company
Do you know your mocks?
@henri_tremblay
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
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 classification (2014)
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://blog.tremblay.pro
@henri_tremblay

Do you know your mock? - Madras JUG 20171028

Editor's Notes

  • #3 He calls them Test doubles. From the most basic to the more advanced type of mock.
  • #5 I’m Henri Tremblay, I’m also the founder of the PerfUG in Paris. I am now one of the Montreal Jug leaders, so if you ever pass by, come say hello and present something. Finally, I’m also involved in Devoxx4kids Québec. Thank you very much for attending, I hope it was useful and I hope you had fun. My favourite question after a talk so I can know if I should keep doing it, is
  • #6 He calls them Test doubles. From the most basic to the more advanced type of mock.
  • #11 A true mock is a mock that knows how to verify itself. In fact, EasyMock and Mockito mocks are always true mocks. So their implementations of a true mock is the same as for the spy.
  • #20 About Ehcache, version 3 has been out for a while now. It is obviously faster, safer, nicer. Please have a look and give us feedback. This is the end, do you have any question?