Working with Mockito and Eclipse
-
Upload
jose-castro -
Category
Technology
-
view
6.389 -
download
4
description
Transcript of Working with Mockito and Eclipse
![Page 1: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/1.jpg)
hugeinc.com [email protected] 45 Main St. #220 Brooklyn, NY 11222 +1 718 625 4843
Sep 1, 2011 Working with Mockito
![Page 2: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/2.jpg)
Agenda: 1. What is Mockito 2. Why use it 3.
Writing Tests
![Page 3: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/3.jpg)
Fewer defects, less debugging, more confidence, better design,
and higher productivity -- Kent Beck --
![Page 4: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/4.jpg)
State Testing: assertEquals(“joe”, user.getName())
4.
![Page 5: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/5.jpg)
Interaction Testing: verify(mockedDao).execute(criteria)
5.
![Page 6: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/6.jpg)
• Test Stub
• Mock object
• Test Spy
Terminology
6.
![Page 7: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/7.jpg)
• What we’re doing on BigShipCruises
• Profile – a simple value object.
• FindProfileDao – handles data access.
• ProfileFacade – bridges requests from ws.
Mockito Examples
7.
![Page 8: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/8.jpg)
Eclipse generates the profileFacade method
First writing the test
8.
![Page 9: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/9.jpg)
Then you implement the method
You run the test and Bang! It fails!
9.
![Page 10: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/10.jpg)
You run the test and it passes!
10.
![Page 11: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/11.jpg)
Eclipse generates the profileFacade method
Checking method invocation
11.
![Page 12: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/12.jpg)
You run the test and Bang! It fails! Again!
12.
![Page 13: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/13.jpg)
And tests pass!
Implement the method
13.
![Page 14: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/14.jpg)
8.4 Tests/second Unit
14.
1.8 Tests/second Integration
![Page 15: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/15.jpg)
mockito.org Learn More:
![Page 16: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/16.jpg)
Questions…
![Page 17: Working with Mockito and Eclipse](https://reader034.fdocuments.net/reader034/viewer/2022042623/54c3899e4a7959eb048b466a/html5/thumbnails/17.jpg)
hugeinc.com [email protected] 45 Main St. #220 Brooklyn, NY 11222 +1 718 625 4843