tdd with babymock 2

15
Test-driven development in with BabyMock 2 Attila Magyar FOSDEM 01/02/2014 Brussels

Upload: attila-magyar

Post on 03-Jul-2015

569 views

Category:

Technology


0 download

DESCRIPTION

BabyMock is a visual mock object library for Pharo Smalltalk, that supports test-driven development. http://youtu.be/xChlI4j4Euc

TRANSCRIPT

Page 1: TDD with BabyMock 2

Test-driven development inwith BabyMock 2

Attila MagyarFOSDEM 01/02/2014Brussels

Page 2: TDD with BabyMock 2

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

Page 3: TDD with BabyMock 2

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

Page 4: TDD with BabyMock 2

Outside-in TDD with Mocks

A

B

C

Message 3

Message 4

Message 1

Response

Test Message 2

Page 5: TDD with BabyMock 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

Page 6: TDD with BabyMock 2

● 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/

Page 7: TDD with BabyMock 2

The old syntax (BabyMock 1)

Page 8: TDD with BabyMock 2

The new syntax (BabyMock 2)

Page 9: TDD with BabyMock 2

ExpectationsUnder the hood

Page 10: TDD with BabyMock 2

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.

Page 11: TDD with BabyMock 2

BabyMock visualized with BabyMock

Page 12: TDD with BabyMock 2

BabyMock visualized with BabyMock

Page 13: TDD with BabyMock 2

BabyMock visualized with BabyMock

Page 14: TDD with BabyMock 2

DEMO

ShoppingCart

● CreditCard

● PriceCatalog

● Adding new item ids

● Paying for its content

Page 15: TDD with BabyMock 2

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.