Icare Design 2009 2009 Icare Design
Jmock, outils et astuces
Mohammed Boukoutaya
Alcatel-Lucent Services for Enterprise
All Rights Reserved © Alcatel-Lucent 2007
Plan
1. Les prérequis 2. La philosophie 3. L’utilisation de Jmock
All Rights Reserved © Alcatel-Lucent 2007
Icare Design 2009
Les prérequis
Alcatel-Lucent Services for Enterprise
All Rights Reserved © Alcatel-Lucent 2007
IDE : eclipse. JDK 1.6 ou autre La JavaDoc de Jmock La bibliothèque Jmock 2.5.1
All Rights Reserved © Alcatel-Lucent 2007
La philosophie
5 | Presentation Title | Month 2007
All Rights Reserved © Alcatel-Lucent 2007
La philosphie
B A
C
All Rights Reserved © Alcatel-Lucent 2007
La philosphie
Les généralité d’utilisation
Accès complexe, DataBase, Utilisation de bibliothèques tierces
All Rights Reserved © Alcatel-Lucent 2007
L’utilisation
8 | Presentation Title | Month 2007
All Rights Reserved © Alcatel-Lucent 2007
Utilisation
The invocation is expected once and once only.
one exactly(n).of
The invocation is expected exactly n times. Note: one is a convenient shorthand for exactly(1).
atLeast(n).of
The invocation is expected at least n times.
atMost(n).of
The invocation is expected at most n times.
between(min, max).o The invocation is expected at least min times and at most max times. f allowing
The invocation is allowed any number of times but does not have to happen.
ignoring
The same as allowing. Allowing or ignoring should be chosen to make the test code clearly express intent.
never
The invocation is not expected at all. This is used to mak
All Rights Reserved © Alcatel-Lucent 2007
Utilisation
context = new Mockery() { { setImposteriser(ClassImposteriser.INSTANCE); } }; final SearchUdaService searchUdaMock = context.mock(SearchUdaService.class); context.checking(new Expectations() { { one(mockStub).searchByFullName(with(any(SearchByFullNameRequest.class))); will(returnValue(searchByFullNameResponse)); });
All Rights Reserved © Alcatel-Lucent 2007
www.alcatel-lucent.com
11 | Presentation Title | Month 2007
All Rights Reserved © Alcatel-Lucent 2007