Post on 24-Jan-2015
description
hugeinc.com info@hugeinc.com 45 Main St. #220 Brooklyn, NY 11222 +1 718 625 4843
Sep 1, 2011 Working with Mockito
Agenda: 1. What is Mockito 2. Why use it 3.
Writing Tests
Fewer defects, less debugging, more confidence, better design,
and higher productivity -- Kent Beck --
State Testing: assertEquals(“joe”, user.getName())
4.
Interaction Testing: verify(mockedDao).execute(criteria)
5.
• Test Stub
• Mock object
• Test Spy
Terminology
6.
• What we’re doing on BigShipCruises
• Profile – a simple value object.
• FindProfileDao – handles data access.
• ProfileFacade – bridges requests from ws.
Mockito Examples
7.
Eclipse generates the profileFacade method
First writing the test
8.
Then you implement the method
You run the test and Bang! It fails!
9.
You run the test and it passes!
10.
Eclipse generates the profileFacade method
Checking method invocation
11.
You run the test and Bang! It fails! Again!
12.
And tests pass!
Implement the method
13.
8.4 Tests/second Unit
14.
1.8 Tests/second Integration
mockito.org Learn More:
Questions…
hugeinc.com info@hugeinc.com 45 Main St. #220 Brooklyn, NY 11222 +1 718 625 4843