17
hugeinc.com [email protected] 45 Main St. #220 Brooklyn, NY 11222 +1 718 625 4843 Sep 1, 2011 Working with Mockito

Working with Mockito and Eclipse

Embed Size (px)

DESCRIPTION

Small presentation about using mockito on an environment where you're using eclipse as your main development tool.This shows somehow to use tdd while using eclipse that creates a bunch of code for you.

Citation preview

Page 1: Working with Mockito and Eclipse

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

Agenda: 1. What is Mockito 2. Why use it 3.

Writing Tests

Page 3: Working with Mockito and Eclipse

Fewer defects, less debugging, more confidence, better design,

and higher productivity -- Kent Beck --

Page 4: Working with Mockito and Eclipse

State Testing: assertEquals(“joe”, user.getName())

4.

Page 5: Working with Mockito and Eclipse

Interaction Testing: verify(mockedDao).execute(criteria)

5.

Page 6: Working with Mockito and Eclipse

• Test Stub

• Mock object

• Test Spy

Terminology

6.

Page 7: Working with Mockito and Eclipse

•  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

Eclipse generates the profileFacade method

First writing the test

8.

Page 9: Working with Mockito and Eclipse

Then you implement the method

You run the test and Bang! It fails!

9.

Page 10: Working with Mockito and Eclipse

You run the test and it passes!

10.

Page 11: Working with Mockito and Eclipse

Eclipse generates the profileFacade method

Checking method invocation

11.

Page 12: Working with Mockito and Eclipse

You run the test and Bang! It fails! Again!

12.

Page 13: Working with Mockito and Eclipse

And tests pass!

Implement the method

13.

Page 14: Working with Mockito and Eclipse

8.4 Tests/second Unit

14.

1.8 Tests/second Integration

Page 15: Working with Mockito and Eclipse

mockito.org Learn More:

Page 16: Working with Mockito and Eclipse

Questions…

Page 17: Working with Mockito and Eclipse

hugeinc.com [email protected] 45 Main St. #220 Brooklyn, NY 11222 +1 718 625 4843