shallow depth of tests scallable bdd and tdd

52
Shallow Depth of Test Scalable TDD/BDD www.fabiopereira.me

Upload: fabiopereirame

Post on 24-May-2015

661 views

Category:

Economy & Finance


1 download

DESCRIPTION

http://fabiopereira.me/blog/2012/02/05/speaking-at-qcon-beijing/QCon Beijing presentation.Shallow Depth of Tests - Scalable TDD/BDDTest automation is prevalent in the software development community. Practices like TDD and BDD are widespread and applied almost unquestionably. However, several organisations have struggled in attempting to scale automated test suites, which very often become slow, brittle, non-deterministic, unreliable and difficult to maintain.In this talk, I will discuss some common mistakes, Tautological TDD (TTDD), for example, and also present patterns that I have successfully applied, such as Shallow Depth of Tests and Testing Pyramid. These have enabled us to achieve maintainable and scalable tests that fulfill their purpose - to help software development teams deliver faster and more confidently the features required by business people.

TRANSCRIPT

Page 1: Shallow Depth of Tests Scallable BDD and TDD

Shallow Depth of Test Scalable TDD/BDD  

www.fabiopereira.me  

Page 2: Shallow Depth of Tests Scallable BDD and TDD

TDD Call Centre  

• Slow • Brittle • Non-deterministic • Difficult to maintain • They do not scale

Page 3: Shallow Depth of Tests Scallable BDD and TDD

No Tests

TODAY  

???????  

TDD Evolution  

Page 4: Shallow Depth of Tests Scallable BDD and TDD

Quote System  

29 year old man wants: -  Car insurance -  Travel insurance

Car $25 Travel $15

Page 5: Shallow Depth of Tests Scallable BDD and TDD

Quote System  

62 year old man wants: -  Car insurance -  Travel insurance

Car $25 Travel (Too Old)

Page 6: Shallow Depth of Tests Scallable BDD and TDD

Quote System  

Can sell car insurance to people between 18 and 65. Can sell travel insurance to people between 18 and 60

Travel 17 L 18 J 60 J 61 L

Car 17 L 18 J 60 J 61 J 65 J 66 L

Page 7: Shallow Depth of Tests Scallable BDD and TDD

Internet

Quote System  

Page 8: Shallow Depth of Tests Scallable BDD and TDD

Controller  Domain Model  

JavaScript  

Repository  

WebServer ReverseProxies Authentication

JSON Services  

Page 9: Shallow Depth of Tests Scallable BDD and TDD

Controller   Quote Pricing   Validator   Mandatory

Validator  

BusRule Validator  

BR1 BR2 BRN …  

Domain Model  

Validations  

Price Calculator  

Cover1 Cover2 …  

PRICING DATA

Pricer  Error Handler  

Repository  

JSON

Page 10: Shallow Depth of Tests Scallable BDD and TDD

Controller   Quote Pricing   Validator   Mandatory

Validator  

BusRule Validator  

BR1 BR2 BRN …  

Domain Model  

Validations  

Price Calculator  

Cover1 Cover2 …  

PRICING DATA

Pricer  Error Handler  

Repository  

JSON

Age Restriction Rule  

Page 11: Shallow Depth of Tests Scallable BDD and TDD

Controller   Quote Pricing   Validator   Mandatory

Validator  

BusRule Validator  

BR1 BR2 BRN …  

Domain Model  

Validations  

Price Calculator  

Cover1 Cover2 …  

PRICING DATA

Pricer  Error Handler  

Repository  

JSON

Page 12: Shallow Depth of Tests Scallable BDD and TDD
Page 13: Shallow Depth of Tests Scallable BDD and TDD
Page 14: Shallow Depth of Tests Scallable BDD and TDD
Page 15: Shallow Depth of Tests Scallable BDD and TDD

h#p://blogs.agilefaqs.com/  

Most  so6ware  organiza;ons  today  suffer  from  what  I    called  the  “Inverted  Tes+ng  Pyramid”  (…)  

Page 16: Shallow Depth of Tests Scallable BDD and TDD

h#p://jamescrisp.org  

Page 17: Shallow Depth of Tests Scallable BDD and TDD
Page 18: Shallow Depth of Tests Scallable BDD and TDD

h#p://clipboarded.blogspot.com  

Page 19: Shallow Depth of Tests Scallable BDD and TDD
Page 20: Shallow Depth of Tests Scallable BDD and TDD
Page 21: Shallow Depth of Tests Scallable BDD and TDD

Controller   Quote Pricing   Validator   Mandatory

Validator  

BusRule Validator  

BR1 BR2 BRN …  

Domain Model  

Validations  

Price Calculator  

Cover1 Cover2 …  

PRICING DATA

Pricer  Error Handler  

Repository  

JSON

Age Restriction Rule  

Page 22: Shallow Depth of Tests Scallable BDD and TDD

Shallow Depth of Test  

Page 23: Shallow Depth of Tests Scallable BDD and TDD

Shallow Depth of Test  

Page 24: Shallow Depth of Tests Scallable BDD and TDD

MyTest  

Mock/Stub  

Stimulate  

Operate  

Simulate  

Page 25: Shallow Depth of Tests Scallable BDD and TDD

Controller   Quote Pricing   Validator   Mandatory

Validator  

BusRule Validator  

BR1 BR2 BRN …  

Domain Model  

Validations  

Price Calculator  

Cover1 Cover2 …  

PRICING DATA

Pricer  Error Handler  

Repository  

JSON

Page 26: Shallow Depth of Tests Scallable BDD and TDD

www.fabiopereira.me  

Page 27: Shallow Depth of Tests Scallable BDD and TDD
Page 28: Shallow Depth of Tests Scallable BDD and TDD

Business   Devs  Broker  Renewal  Risk  

Address  Insurer  

 

user  Edit  

UBD_CD  TB_ADR  en:ty  

BDD  

Page 29: Shallow Depth of Tests Scallable BDD and TDD

Given When Then

B D D

Page 30: Shallow Depth of Tests Scallable BDD and TDD

BDD at the Unit Level  

Page 31: Shallow Depth of Tests Scallable BDD and TDD

Use Builders and Fixtures  

h#p://en.wikipedia.org/wiki/Builder_pa#ern  

Page 32: Shallow Depth of Tests Scallable BDD and TDD

BDD  

Concept  

Tools/ Current Practices  

Page 33: Shallow Depth of Tests Scallable BDD and TDD

h#p://blog.carbonfive.com/2011/11/07/modern-­‐cucumber-­‐and-­‐rails-­‐no-­‐more-­‐training-­‐wheels/  

web_steps.rb  

Page 34: Shallow Depth of Tests Scallable BDD and TDD

Simulate Http  

Page 35: Shallow Depth of Tests Scallable BDD and TDD

Wiring

Page 36: Shallow Depth of Tests Scallable BDD and TDD

IN MEMORY DB (HSQL)

Page 37: Shallow Depth of Tests Scallable BDD and TDD

You can test Spring Config  

Page 38: Shallow Depth of Tests Scallable BDD and TDD

High level and Test Journeys at the UI Level

An authenticated insurance advisershould be able to sell insurance to a customer who fulfills all mandatory requirementsBusiness rules should be applied toall customers who attempt to buy insuranceCustomers should be given the right insurance premium based on their insurance requirements

Page 39: Shallow Depth of Tests Scallable BDD and TDD

High level and Test Journeys at the UI Level

An authenticated insurance adviser, should be able to sell insurance to a customer who fulfills all mandatory requirementsBusiness rules should be applied toall customers who attempt to buy insuranceCustomers should be given the right insurance premium based on their insurance requirements

Page 40: Shallow Depth of Tests Scallable BDD and TDD

High level and Test Journeys at the UI Level

An authenticated insurance adviser, should be able to sell insurance to a customer who fulfills all mandatory requirementsBusiness rules should be applied toall customers who attempt to buy insuranceCustomers should be given the right insurance premium based on their insurance requirements

Page 41: Shallow Depth of Tests Scallable BDD and TDD
Page 42: Shallow Depth of Tests Scallable BDD and TDD

TTDD – Tautological TDD  

Tauto… WHAT?!

Page 43: Shallow Depth of Tests Scallable BDD and TDD

Tautology:  from  Greek:  tauto:  the  same    logos:  word/idea            Tautological:  -­‐  needless,  redundant  repe;;on  of  an  idea  -­‐  repe;;on  of  same  sense  in  different  words;  -­‐  the  phrase  ”a  beginner  who  has  just  started”  is  tautological  

Page 44: Shallow Depth of Tests Scallable BDD and TDD

T  A  U  T  O  L  O  G  I  C  A  L  

Page 45: Shallow Depth of Tests Scallable BDD and TDD
Page 46: Shallow Depth of Tests Scallable BDD and TDD

TTDD – Mocks  

Setup Mocks

Call a method/function

Assert that mocks were called

Page 47: Shallow Depth of Tests Scallable BDD and TDD
Page 48: Shallow Depth of Tests Scallable BDD and TDD

(Dependency Injection Code)

   

Page 49: Shallow Depth of Tests Scallable BDD and TDD

(Mocks Setup)  

 

Page 50: Shallow Depth of Tests Scallable BDD and TDD

No Tests

Slow, brittle, etc  

Shallow DoT Test Pyramid Unit BDD UI Journeys Stop TTDD  

Let’s evolve…  

Page 51: Shallow Depth of Tests Scallable BDD and TDD

www.fabiopereira.me  

Page 52: Shallow Depth of Tests Scallable BDD and TDD

References h#p://apcj.blogspot.com/2005_04_01_archive.html  h#p://wa;rmelon.com  h#p://jamescrisp.org  h#p://clipboarded.blogspot.com  h#p://anton.kovalyov.net/2011/02/20/why-­‐i-­‐forked-­‐jslint-­‐to-­‐jshint/  h#p://en.wikipedia.org/wiki/Builder_pa#ern  h#p://jawr.java.net/  h#p://pivotal.github.com/jasmine/  h#p://code.google.com/p/js-­‐test-­‐driver/  h#p://blogs.agilefaqs.com/  h#p://fabiopereira.me/blog/2012/03/18/introducing-­‐depth-­‐of-­‐test-­‐dot/  

Images  h#p://www.flickr.com/photos/nburrows  h#p://www.luxury-­‐insider.com/uploads/news/2010/06/korean-­‐air-­‐first-­‐class-­‐award-­‐1.jpg  h#p://one7.files.wordpress.com/2010/06/browsers.jpg  h#p://www.luxury-­‐insider.com/uploads/news/2010/06/korean-­‐air-­‐first-­‐class-­‐award-­‐1.jpg  h#p://www.digital-­‐photography-­‐student.com/wp-­‐content/uploads/2009/01/DOF-­‐Shallow-­‐Deep.png  h#p://www.flickr.com/photos/bullgod/2604300680/  h#p://www.whatsgo#ago.com/wp-­‐content/uploads/2007/12/angry_phone2.jpg    

Thanks  

www.fabiopereira.me