@MockitoJava@mockitoguy
Mockito 2Cleaner Tests and Enhanced Productivity
JavaOne, San Francisco, 10-2017
● Szczepan Faber
● @mockitoguy
● Creator of Mockito
● Core dev of Gradle 1.x and 2.x
● Tech Lead at LinkedIn Dev Tools
● Author on LinkedIn
News:
● Mockito has 10 years!
● Test First Immersion
workshop at QCon next
month (11/16)
● Join Shipkit - new Open
Source project used by
Mockito: http://shipkit.org
● Also, my team
@LinkedInEng is hiring!
@MockitoJava@mockitoguy
2008No way to write clean tests
with Mocks.
Mockito 1.0 ships.
@MockitoJava@mockitoguy
2017Estimated 2M users
Probably top 3 java library
@MockitoJava@mockitoguy
Combined result puts Mockito on 3rd place!
@MockitoJava@mockitoguy
Oct 2016Mockito 2.0 is out!
Thanks to community and ...
@MockitoJava@mockitoguy
Mockito 2cleaner tests
Writing dirty tests or clean tests
takes same effort
but different level of discipline
@MockitoJava@mockitoguy
Live coding!● GitHub:
szczepiq/mockito-conferences-2017
”javaone” git branch
● Test-driving initial test class video:
https://vimeo.com/209683202
@MockitoJava@mockitoguy
● Debug faster but kill clarity and
long term maintainability
Strict Mocks
@MockitoJava@mockitoguy
● Easier debugging
● Clean tests:
○ DRY - verify stubs
○ No dead test code
(unused stubs)
Mockito v2Strict stubbing
@MockitoJava@mockitoguy
● Java 8 support (lambda, defender
methods)
● Built-in support of mocking finals
● API tweaks like better behavior of
any(), argument captor
● Built-in android support
● Replaced CGLIB with ByteBuddy
● New APIs for extending Mockito
Other features of v2
@MockitoJava@mockitoguy
● Please contribute!
○ 16 tickets ready to contribute
● New integration APIs for other
frameworks:
○ Powermock (3-month project,
shout out to Arthur Zagredtinov)
○ Spring Boot (almost finished)
● Even better strictness
○ Optional truly strict mocks
○ Optional stubs, excluded from
strict checks
● Improve final mocking
Current development
@MockitoJava@mockitoguy
Mockito releasesBy Shipkit
● Shipkit - toolkit for shipping it
● Practical Continuous Delivery
toolkit for Java libraries
● Passionate about release
automation? Join us!!!
● http://shipkit.org
@MockitoJava@mockitoguy
Your TemplateFor Great Tests
● Write given-when-then comments
● Apply them consistently in every
test
● In a few weeks you will notice
tests in your team getting better!
● It does not matter if you believe it
will work. It will work anyway
@MockitoJava@mockitoguy
You deserve great tools
Our talks at JavaOne
● Mockito 2 For Cleaner Tests and Enhanced Productivity
○ This talk. Hope you liked it!
○ I would really appreciate feedback!
○ GitHub: szczepiq/mockito-conferences-2017
● Play on Gradle - Midtier behind linkedin.com
○ Right after this talk, at 12:45 in Room 2012
○ Lessons learned from driving disruptive change
in large org
○ Replacing the heart of Play Framework with
Gradle at scale
● Commit-to-production pipeline at LinkedIn
○ video+slides on slideshare.net
○ Stay tuned for video and @LinkedEng blog
article
@MockitoJava@mockitoguy
Thank you!!!Any questions?
You deserve great tools - Mockito 2 for cleaner tests and enhanced productivityJavaOne, San Francisco, 10-2017
● Szczepan Faber
● @mockitoguy
● Creator of Mockito
● Core dev of Gradle 1.x and 2.x
● Tech Lead at LinkedIn Dev Tools
● Author on LinkedIn
News:
● Mockito has 10 years!
● Test First Immersion
workshop at QCon next
month (11/16)
● Join Shipkit - new Open
Source project used by
Mockito: http://shipkit.org
● Also, my team
@LinkedInEng is hiring!