Test-driven development in
with BabyMock 2

Attila Magyar
FOSDEM 01/02/2014
Brussels
Who am I?

Attila Magyar
●

Java for living

●

Smalltalk for joy, since 2012
●

●

Python, Groovy, Lisp, etc..

TDD for about 4 years
Contact:
http://twitter.com/zeroflag
Agenda

●

●

●

About TDD and Mock objects in general
About BabyMock 2
● Differences between the new and the old version
● How does it work?
● Few words about the internals
DEMO
Outside-in TDD with Mocks

B
3
age
ss
Me

Message 2

A
Me
ssa
ge
4

R
es
po
ns
e

Test

Message 1

C
Expect Message 3
●
Exactly once
●
With x argument
●

Outside-in TDD with Mocks

MOCK B
3
age
ss
Me

Message 2

Allow Message 4
● Any number of times
● With y argument
● Answer „Response”

A

●

Me
ssa
ge
4

R
es
po
ns
e

Test

Message 1

Inter-object protocol

MOCK C
BabyMock is a visual mock object library
http://smalltalkhub.com/#!/~zeroflag/BabyMock2/

Get a good mental picture of the objects relationships, and
the inter-object protocol
●

●

Identifying test failures is easier
The old syntax (BabyMock 1)
The new syntax (BabyMock 2)
Expectations
Under the hood
How does it work?
●

●

●

Mock object is a Proxy that intercepts all messages
Using the doesNotUnderstand is easiest way to implement it
(but limited).
Nil methodDictionary + cannotInterpret
More information:
Efficient Proxies in Smalltalk by Mariano Martinez Peck et al.
BabyMock visualized with BabyMock
BabyMock visualized with BabyMock
BabyMock visualized with BabyMock
DEMO

ShoppingCart
●

Adding new item ids

●

CreditCard

●

Paying for its content

●

PriceCatalog
Food for thought

●

http://jmock.org/
(https://github.com/jmock-developers/jmock-library)

●

Evolving an Embedded Domain-Specific Language in Java, Freeman, S. and Pryce, N.

●

Mock Roles, Not Objects. OOPSLA 2004, Freeman, S., Mackinnon, T., Pryce, N., Walnes, J.,

●

Growing Object-Oriented Software, Guided by Tests, Freeman, S. and Pryce, N.

●

Efficient Proxies in Smalltalk, Mariano Martinez Peck et al.

TDD with BabyMock 2