tdd with babymock 2
DESCRIPTION
BabyMock is a visual mock object library for Pharo Smalltalk, that supports test-driven development. http://youtu.be/xChlI4j4EucTRANSCRIPT
Test-driven development inwith BabyMock 2
Attila MagyarFOSDEM 01/02/2014Brussels
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
A
B
C
Message 3
Message 4
Message 1
Response
Test Message 2
Outside-in TDD with Mocks
A
MOCK B
MOCK C
Message 3
Message 4
Message 1
Response
Test Message 2
●Expect Message 3● Exactly once● With x argument
●Allow Message 4● Any number of times● With y argument● Answer „Response”
Inter-object protocol
● Get a good mental picture of the objects relationships, and the inter-object protocol
● Identifying test failures is easier
BabyMock is a visual mock object libraryhttp://smalltalkhub.com/#!/~zeroflag/BabyMock2/
The old syntax (BabyMock 1)
The new syntax (BabyMock 2)
ExpectationsUnder 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 + cannotInterpretMore 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
● CreditCard
● PriceCatalog
● Adding new item ids
● Paying for its content
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.