Mockist vs. Classicist TDD 
Softwerkskammer Regionalgruppentreffen München 
30.10.2014 
David Völkel
Agenda 
●Theory 
●Pizza 
●Kata
Classicists vs. Mockists 
●Who knows?
Classicists vs. Mockists 
●Who knows? 
●Who leverages what?
Mockists?
Classicists?
How i stumbled upon… 
●#GOOS 
●#IsTDDDead 
●Outside-In  
●Mocking  
●=> How work Classicist?
Classicists 
●„old school“: Kent Beck, Uncle Bob, … 
●state verification 
●bottom-up/inside-out 
●Avoid mocks when possible
Mockists 
●„London School“: Steve Freeman, Nat Pryce 
●XP 2000 „Endo-Testing: Unit Testing with Mock Objects “ 
●OOPSLA 2004 „Mock Roles, not Objects“ 
●Book „Growing Object Oriented Software“ #GOOS 2009
Mockists 
●ATDD 
●Outside-In Design 
●Hexagonal / Ports&Adapters Architecture 
●also for classicists 
●Mocking to isolate layers 
●Interaction based testing 
●„Back-door“
Architecture 
●Mockist OO-style 
●Message Passing/Event-Architecture 
●Topology / Message flow 
●„Tell don‘t ask“ 
●Classicist FP-style 
●mutable objects encapsulating state 
●pure functions & immutable value objects 
●details: algorithms, logic, conditionals
Layer 
UI 
Domain 
Data Access 
DB
Domain 
Hexagonal / Ports & Adapters 
UI 
Domain Service 
Repository DB Adapter 
DB 
Repository Interface
Hexagonal / Ports & Adapters 
Domain Service 
Repository DB Mock 
DB 
Repository Interface 
Unit Test
ATDD 
From Growing Object-Oriented Software by Nat Pryce and Steve Freeman
Outside-In Design 
UI 
Domain Service 
Repository DB Adapter 
DB 
End2End Test
Outside-In Design 
UI 
Domain Service 
Repository DB Adapter 
DB 
Domain Service Interface 
Unit Test 
End2End Test
Outside-In Design 
UI 
Domain Service 
Repository DB Adapter 
DB 
Repository Interface 
Domain Service Interface 
Unit Test 
Unit Test 
End2End Test
Outside-In Design 
UI 
Domain Service 
Repository DB Adapter 
DB 
Repository Interface 
Domain Service Interface 
Unit Test 
Unit Test 
Integration 
Test 
End2End Test
Classicists Design 
●Bottom-up 
●emergent 
●„TDD as if you meant it“ (YAGNI?) 
●Middle ground? 
●Acceptance tests => Domain
Classicist IO 
out = pureFunction(in); 
object.changeStateBasedOn(in); 
out = object.getState(); 
●Functional 
●State-based
Mockist IO: CQS 
public Object myQuery() { 
return neighbour.query(); 
} 
when(neighbour.query()).thenReturn(in); 
●Queries: Stubbing indirect input
Mockist IO: CQS 
public Object myQuery() { 
return neighbour.query(); 
} 
when(neighbour.query()).thenReturn(in); 
private void myCommand() { 
neighbour.command(out); 
} 
verify(neighbour).command(out); 
●Queries: Stubbing indirect input 
●Commands: Spies check indirect output
Let‘s code! 
●Content: Kata „Game of Life“ 
●Phase 1: Outside-In Mockist style 
●Mockless Classicist design 
●Phase 2: refactor to mockless Classicist design 
●Mode: Mob Programming 
●1 Driver 
●N Navigators 
●Variant: David = PO & facilitator
Outside-In Mockist style
Classicist Isolation 
●No isolation = „front door“ 
●Leaf 
●Integrated test 
●By design 
●Context independence: parameterize methods/constructors, values/value objects, intermediary results 
●„Functional Core, Imperative Shell“
String renderMail(String mail) { 
String name = userRepo.nameFor(mail); 
return renderMailAndName(mail, name); 
} 
@Test public void renderMail() { 
when(userRepo.nameFor("customer@gmail.com")) 
.thenReturn("Joe Customer"); 
assertEquals("customer@gmail.com <Joe Customer>", 
mailService.renderMail("customer@gmail.com")); 
} 
Isolation via mocks
String renderMail(String mail) { 
String name = userRepo.nameFor(mail); 
return renderMailAndName(mail, name); 
} 
@Test public void renderMail() { 
when(userRepo.nameFor("customer@gmail.com")) 
.thenReturn("Joe Customer"); 
assertEquals("customer@gmail.com <Joe Customer>", 
mailService.renderMail("customer@gmail.com")); 
} 
@Test public void renderMail() { 
assertEquals("customer@gmail.com <Joe Customer>", 
mailService.renderMailAndName("customer@gmail.com", "Joe Customer")); 
} 
Mockless isolation
Refactor mocks away
Retrospective
Bilder 
von RaminusFalcon 
http://commons.wikimedia.org/wiki/File:Split- scissors.svg?uselang=de
Lizenz 
Creative Commons Attribution-ShareAlike 3.0 
https://creativecommons.org/licenses/by-sa/3.0/de/
TDD as if you meant it 
1.Write exactly one failing test 
2.Make the test pass by writing implementation code in the test method 
3.When duplication is spotted extract the implementation from tests to: 
1. a new method in the test class 
2.an existing method in the test class 
4.When more methods belong together extract them into a new class 
5.Refactor as required 
by Adi Bolboaca

Mockist vs. Classicists TDD

  • 1.
    Mockist vs. ClassicistTDD Softwerkskammer Regionalgruppentreffen München 30.10.2014 David Völkel
  • 2.
  • 3.
  • 4.
    Classicists vs. Mockists ●Who knows? ●Who leverages what?
  • 5.
  • 6.
  • 7.
    How i stumbledupon… ●#GOOS ●#IsTDDDead ●Outside-In  ●Mocking  ●=> How work Classicist?
  • 8.
    Classicists ●„old school“:Kent Beck, Uncle Bob, … ●state verification ●bottom-up/inside-out ●Avoid mocks when possible
  • 9.
    Mockists ●„London School“:Steve Freeman, Nat Pryce ●XP 2000 „Endo-Testing: Unit Testing with Mock Objects “ ●OOPSLA 2004 „Mock Roles, not Objects“ ●Book „Growing Object Oriented Software“ #GOOS 2009
  • 10.
    Mockists ●ATDD ●Outside-InDesign ●Hexagonal / Ports&Adapters Architecture ●also for classicists ●Mocking to isolate layers ●Interaction based testing ●„Back-door“
  • 11.
    Architecture ●Mockist OO-style ●Message Passing/Event-Architecture ●Topology / Message flow ●„Tell don‘t ask“ ●Classicist FP-style ●mutable objects encapsulating state ●pure functions & immutable value objects ●details: algorithms, logic, conditionals
  • 12.
    Layer UI Domain Data Access DB
  • 13.
    Domain Hexagonal /Ports & Adapters UI Domain Service Repository DB Adapter DB Repository Interface
  • 14.
    Hexagonal / Ports& Adapters Domain Service Repository DB Mock DB Repository Interface Unit Test
  • 15.
    ATDD From GrowingObject-Oriented Software by Nat Pryce and Steve Freeman
  • 16.
    Outside-In Design UI Domain Service Repository DB Adapter DB End2End Test
  • 17.
    Outside-In Design UI Domain Service Repository DB Adapter DB Domain Service Interface Unit Test End2End Test
  • 18.
    Outside-In Design UI Domain Service Repository DB Adapter DB Repository Interface Domain Service Interface Unit Test Unit Test End2End Test
  • 19.
    Outside-In Design UI Domain Service Repository DB Adapter DB Repository Interface Domain Service Interface Unit Test Unit Test Integration Test End2End Test
  • 20.
    Classicists Design ●Bottom-up ●emergent ●„TDD as if you meant it“ (YAGNI?) ●Middle ground? ●Acceptance tests => Domain
  • 21.
    Classicist IO out= pureFunction(in); object.changeStateBasedOn(in); out = object.getState(); ●Functional ●State-based
  • 22.
    Mockist IO: CQS public Object myQuery() { return neighbour.query(); } when(neighbour.query()).thenReturn(in); ●Queries: Stubbing indirect input
  • 23.
    Mockist IO: CQS public Object myQuery() { return neighbour.query(); } when(neighbour.query()).thenReturn(in); private void myCommand() { neighbour.command(out); } verify(neighbour).command(out); ●Queries: Stubbing indirect input ●Commands: Spies check indirect output
  • 24.
    Let‘s code! ●Content:Kata „Game of Life“ ●Phase 1: Outside-In Mockist style ●Mockless Classicist design ●Phase 2: refactor to mockless Classicist design ●Mode: Mob Programming ●1 Driver ●N Navigators ●Variant: David = PO & facilitator
  • 25.
  • 26.
    Classicist Isolation ●Noisolation = „front door“ ●Leaf ●Integrated test ●By design ●Context independence: parameterize methods/constructors, values/value objects, intermediary results ●„Functional Core, Imperative Shell“
  • 27.
    String renderMail(String mail){ String name = userRepo.nameFor(mail); return renderMailAndName(mail, name); } @Test public void renderMail() { when(userRepo.nameFor("customer@gmail.com")) .thenReturn("Joe Customer"); assertEquals("customer@gmail.com <Joe Customer>", mailService.renderMail("customer@gmail.com")); } Isolation via mocks
  • 28.
    String renderMail(String mail){ String name = userRepo.nameFor(mail); return renderMailAndName(mail, name); } @Test public void renderMail() { when(userRepo.nameFor("customer@gmail.com")) .thenReturn("Joe Customer"); assertEquals("customer@gmail.com <Joe Customer>", mailService.renderMail("customer@gmail.com")); } @Test public void renderMail() { assertEquals("customer@gmail.com <Joe Customer>", mailService.renderMailAndName("customer@gmail.com", "Joe Customer")); } Mockless isolation
  • 29.
  • 30.
  • 31.
    Bilder von RaminusFalcon http://commons.wikimedia.org/wiki/File:Split- scissors.svg?uselang=de
  • 32.
    Lizenz Creative CommonsAttribution-ShareAlike 3.0 https://creativecommons.org/licenses/by-sa/3.0/de/
  • 33.
    TDD as ifyou meant it 1.Write exactly one failing test 2.Make the test pass by writing implementation code in the test method 3.When duplication is spotted extract the implementation from tests to: 1. a new method in the test class 2.an existing method in the test class 4.When more methods belong together extract them into a new class 5.Refactor as required by Adi Bolboaca