Upload
dmitry-buzdin
View
1.589
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
Mockito
JUG LatviaDenis Udod
Mochito vs Mockito
Mochito Recipe:
1/12 liter Dark Rum 3 cl Lemon Juice 1/2 handful Mint 1/12 liter Club Soda 8 drops Angostura Bitters
Mochito vs Mockito
Mochito Recipe:
1/12 liter Dark Rum 3 cl Lemon Juice 1/2 handful Mint 1/12 liter Club Soda 8 drops Angostura Bitters
Mockito Recipe:
Java Unit testing Mock object
Mochito vs. Mockito
Mochito Recipe:
1/12 liter Dark Rum 3 cl Lemon Juice 1/2 handful Mint 1/12 liter Club Soda 8 drops Angostura Bitters
Mockito Recipe:
Java Unit testing Mock object
What is the difference?
Mockito: Why drink it?
Q: What is unit testing?
Q: What is a mock-objects?
Q: Why do we mock-objects?
Unit testing - What's the point?
Write simple test for each class method.
Unit testing - What's the point?
Write simple test for each class method.
Unit testing - What's the point?
Write simple test for each class method.
Unit testing - What's the point?
Write simple test for each class method.
• simple• fast• independent from "any" (database, network, filesystem)
Mock object - What's the point?
Simulate the behavior of complex, real(non-mock) objects.
• Useful when a real object is impractical or impossible to incorporate into a unit test.
Mock object - What's the point?
Example - service object supplies non-deterministic results:
Mock object - What's the point?
Example - service object supplies non-deterministic results:
Mockito: Why drink it?
• Mockito is a mocking framework that tastes really well.
• It lets you write beautiful tests with clean & simple API.
• Mockito doesn't give you hangover.
Mockito: Why drink it?
Syntax
• Let’s keep it simple• No Strings for methods.• No anonymous inner classes.• Painless refactoring. Renaming a method should not break
my tests.
Mockito: How to drink it?
1. Download from http://mockito.org 2. Add to project.3. And have fun
Mockito: How to drink it?
Create mock object:
Mockito: How to drink it?
Create mock object:
Mockito: How to drink it?
Create mock object:
Mockito: How to drink it?
How about returned values?
Mockito: How to drink it?
How about returned values?
Mockito: How to drink it?
Check method invocations
Mockito: How to drink it?
Check method invocations
Mockito: How to drink it?
Check method invocations
Mockito: How to drink it?
Check method invocations
Mockito: How to drink it?
Check method invocations
Mockito: How to drink it?
Spying on real object:
Mockito: Hangover?
Limitation:
• needs java 1.5+• Cannot mock final class• Cannot mock static, final methods• Cannot mock equals(),hashCode() metods• Cannot mock private metods• Cannot verify toString()
MockitoWho is your bartender?
Mockito is served to you by Szczepan Faber and friends.www.mockito.org