SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Downloaden Sie, um offline zu lesen
Just	
  Mock	
  It	
  
Mocks	
  and	
  Stubs	
  
Presented by Gavin Pickin
Slides: http://gpickin.com/itb2014/
Website: http://gpickin.com
Twitter: @gpickin
Introduc)on	
  
•  Follow	
  along	
  with	
  resources	
  from	
  
h6p://gpickin.com/itb2014/	
  
	
  
•  If	
  you	
  want	
  to	
  find	
  out	
  more	
  about	
  me,	
  my	
  
website	
  has	
  more	
  than	
  enough	
  informa)on	
  
20	
  Second	
  Agenda	
  
•  Unit	
  Tes)ng	
  -­‐	
  Recap	
  
•  What	
  is	
  Mocking	
  	
  
•  What	
  is	
  a	
  Mock	
  /	
  Stub	
  
•  Why	
  Mock	
  
•  Let’s	
  look	
  at	
  some	
  Mocking	
  
Unit	
  Tes)ng	
  
“unit	
  tes)ng	
  is	
  a	
  soOware	
  verifica)on	
  and	
  
valida)on	
  method	
  in	
  which	
  a	
  programmer	
  tests	
  
if	
  individual	
  units	
  of	
  source	
  code	
  are	
  fit	
  for	
  use.	
  
A	
  unit	
  is	
  the	
  smallest	
  testable	
  part	
  of	
  an	
  
applica)on”	
  
-­‐	
  wikipedia	
  
Unit	
  Tes)ng	
  
•  Can	
  improve	
  code	
  quality	
  -­‐>	
  quick	
  error	
  
discovery	
  
•  Code	
  confidence	
  via	
  immediate	
  verifica)on	
  
•  Can	
  expose	
  high	
  coupling	
  
•  Will	
  encourage	
  refactoring	
  to	
  produce	
  >	
  
testable	
  code	
  
•  Remember:	
  Tes)ng	
  is	
  all	
  about	
  behavior	
  and	
  
expecta)ons	
  
Bugs	
  Hurt	
  
Bugs	
  Hurt	
  
•  Bugs	
  hurt	
  –	
  the	
  later	
  in	
  the	
  process,	
  the	
  
harder	
  to	
  fix.	
  
•  Test	
  Early	
  and	
  OOen	
  
– Find	
  them	
  before	
  they	
  rot	
  your	
  founda)on	
  
•  Testable	
  Code	
  is	
  Maintainable	
  Code	
  
Unit	
  Tes)ng	
  Basics	
  
Test	
  Driven	
  Development	
  
Important	
  Tests	
  
•  Unit	
  Tes)ng	
  
– Test	
  behavior	
  of	
  individual	
  objects	
  
•  Integra)on	
  Tes)ng	
  
– Test	
  En)re	
  Applica)on	
  from	
  Top	
  Down	
  
•  UI	
  verifica)on	
  tes)ng	
  
– Verifica)on	
  via	
  HTML/Visual	
  elements	
  
Important	
  Tes)ng	
  Tools	
  
•  TestBox	
  (Run	
  BDD	
  and	
  MXUnit	
  style)	
  
•  IDE	
  -­‐	
  CF	
  Builder	
  /	
  Eclipse	
  
•  Mocking	
  Framework	
  
•  ANT	
  
•  Jenkins,	
  Bamboo,	
  Teamcity,	
  other	
  Cis	
  
•  Selenium	
  
•  Jmeter	
  or	
  Webstress	
  Tool,	
  Apache	
  AB	
  	
  
What	
  is	
  Mocking?	
  
According	
  to	
  Merriam	
  Webster	
  
•  to	
  laugh	
  at	
  or	
  make	
  fun	
  of	
  (someone	
  or	
  
something)	
  especially	
  by	
  copying	
  an	
  ac)on	
  or	
  
a	
  way	
  of	
  behaving	
  or	
  speaking	
  
•  to	
  imitate	
  (as	
  a	
  mannerism)	
  closely	
  	
  
What	
  is	
  Mocking?	
  
"A	
  mock	
  object	
  is	
  an	
  object	
  that	
  takes	
  the	
  place	
  
of	
  a	
  ‘real’	
  object	
  in	
  such	
  a	
  way	
  that	
  makes	
  
tes)ng	
  easier	
  and	
  more	
  meaningful,	
  or	
  in	
  some	
  
cases,	
  possible	
  at	
  all"	
  
by	
  Sco6	
  Bain	
  -­‐	
  Emergent	
  Design	
  
Mocks	
  
Mocks	
  
Mocks	
  
Mocks	
  
Stub	
  Object	
  
•  A	
  stub	
  is	
  an	
  empty	
  container,	
  that	
  represents	
  
an	
  Object.	
  
•  This	
  can	
  be	
  useful	
  for	
  represen)ng	
  CFCs	
  and	
  
Objects	
  that	
  haven’t	
  been	
  wri6en	
  yet.	
  
Why	
  use	
  Mocking	
  
•  Isolate	
  your	
  SUT	
  -­‐>	
  SoOware	
  Under	
  Test	
  
•  To	
  build	
  against	
  interfaces	
  &	
  contracts	
  
•  Building	
  against	
  missing	
  integra)on	
  pieces	
  
•  To	
  control	
  data	
  and	
  expecta)ons	
  
•  Mock	
  components	
  whose	
  behavior	
  is	
  
undesirable	
  or	
  hard	
  to	
  control	
  
Why	
  Mock?	
  
•  How	
  do	
  you	
  test	
  when	
  helper	
  components	
  
that	
  are	
  not	
  built	
  yet?	
  
•  How	
  do	
  you	
  do	
  controlled	
  excep)ons?	
  
•  How	
  do	
  you	
  test	
  &	
  control	
  external	
  API	
  calls?	
  
•  How	
  do	
  you	
  control	
  results	
  from	
  ColdFusion	
  
tags	
  or	
  func)ons?	
  
•  How	
  do	
  you	
  control	
  network	
  connec)ons?	
  Do	
  
you	
  pull	
  the	
  network	
  plug?	
  
Why	
  Mock?	
  
How	
  do	
  you	
  test	
  code	
  like	
  this?	
  
	
  
<cfdirectory	
  ac)on=”list”	
  directory=”#arguments.path#”	
  name=”qResults”>	
  
<ck6p	
  url=”#arguments.urlPath#”	
  results=”qResults”>	
  
<cfmail	
  to=”#to#”	
  from=”#from#”	
  subject=”#subject#”>#content#</cfmail>	
  
<cfquery	
  />	
  
func)on	
  init(){	
  
var	
  helper	
  =	
  new	
  Helper();	
  
}	
  
private	
  func)on	
  getData(){	
  return	
  data;	
  }	
  
The	
  COLD	
  hard	
  truth	
  –	
  It	
  can	
  Hurt	
  
•  Tes)ng	
  some	
  code	
  is	
  hard,	
  or	
  almost	
  
impossible.	
  	
  
•  Refactor	
  it	
  
•  Mock	
  it	
  
•  Test	
  It	
  
•  With	
  CI,	
  you	
  can	
  forget	
  about	
  it	
  
	
  Un)l	
  it	
  breaks	
  
Refactor	
  to	
  make	
  it	
  Mockable	
  
•  Original:	
  
<cfdirectory	
  ac)on=”list”	
  directory=”/myapp/path”	
  name=”qResults”>	
  
•  Refactored	
  
<cffunc)on	
  name=”getFiles”	
  output=”false”	
  returnType=”query”>	
  
	
  	
  	
  	
  <cfargument	
  name=”path”>	
  
	
  	
  	
  	
  <cfset	
  var	
  qResults	
  =	
  “”>	
  
	
  	
  	
  	
  <cfdirectory	
  ac)on=”list”	
  directory=”#arguments.path#”	
  name=”qResults”>	
  
	
  	
  	
  	
  ...	
  Process	
  Here	
  ...	
  
	
  	
  	
  	
  <cfreturn	
  qResults>	
  
</cffunc)on>	
  
Normal	
  View	
  of	
  your	
  Service	
  
Mock/Test	
  View	
  of	
  your	
  Service	
  
What	
  do	
  we	
  Mock?	
  
•  Excep)ons	
  
•  Data	
  
•  CFC	
  and	
  Objects	
  
•  Methods	
  in	
  our	
  CFCs	
  
•  Proper)es	
  in	
  our	
  CFCs	
  
Mocking	
  Framework	
  
•  Introducing	
  
What	
  can	
  MockBox	
  do?	
  
•  Mock	
  Objects	
  with	
  or	
  without	
  implementa)ons	
  
•  Mock	
  methods	
  &	
  proper)es	
  in	
  any	
  scope	
  
•  Create	
  Stub	
  Objects	
  -­‐>	
  Non-­‐existent	
  objects	
  
•  Mock	
  excep)ons	
  
•  Mock	
  arguments	
  to	
  results	
  
•  Logging	
  &	
  Debugging	
  
•  Verifica)on	
  methods	
  
•  State	
  Machine	
  Results	
  
Sepng	
  up	
  MockBox	
  
•  Standalone	
  Version	
  (FW/1,	
  Fusebox,	
  Model	
  
Glue,	
  Home	
  Brewed)	
  
mockBox	
  =	
  
createObject(“component”,”mockBox.system.tes)ng.MockBox”).init();	
  
	
  
•  Running	
  from	
  inside	
  ColdBox	
  (outside	
  of	
  TestBox)	
  
mockBox	
  =	
  
createObject(“component”,”coldbox.system.tes)ng.MockBox”).init();	
  
Using	
  MockBox	
  
•  MockBox	
  does	
  its	
  magic	
  dynamically,	
  adding	
  /	
  
decora)ng	
  CFCs	
  with	
  necessary	
  methods.	
  	
  
•  CreateMock()	
  
user	
  =	
  mockBox.createMock(“model.User”);	
  
•  CreateEmptyMock()	
  
dao	
  =	
  mockBox.createEmptyMock(“model.UserDAO”);	
  
•  PrepareMock()	
  
mockBox.prepareMock(	
  service	
  );	
  
Using	
  MockBox	
  -­‐	
  Stubs	
  
•  CreateStub()	
  
–  Create	
  a	
  simple	
  empty	
  Stub	
  
–  Pass	
  an	
  Implements	
  to	
  get	
  a	
  Mock	
  Interface	
  
–  Pass	
  an	
  Extends	
  to	
  get	
  a	
  Mock	
  with	
  Inheritance	
  
	
  
nonExistentService	
  =	
  mockBox.createStub();	
  
mockInterface	
  =	
  mockBox.createStub(implements=”model.ICache”);	
  
mockInheritance	
  =	
  mockbox.createStub(extends=”model.SecurityService”);	
  
Injected	
  Methods	
  
$()	
  
•  Argument	
  
–  method	
  
–  returns	
  
–  preserveReturnType	
  
–  throwExcep)on	
  
–  throwType	
  
–  throwDetail	
  
–  throwMessage	
  
–  callLogging	
  
// Cascaded mocks
mockUser.$(“isFound”,true).$(“isDirty”,true);
// Mock Exception
mockUser.
$(method=”save”,
throwsException=true,
throwType=”IllegalStateException”,
throwMessage=”Invalid User Data”);
// Mock Return Objects
mockRole = mockBox.createMock(“Role”);
service.$
(method=”getRole”,returns=mockRole);
Using	
  $()	
  
mockUser	
  =	
  mockBox.createEmptyMock(“model.User”).init();	
  
userService	
  =	
  mockBox.createMock(“model.UserService”).init();	
  
user	
  =	
  userService.$(“get”,	
  mockUser);	
  
	
  
//Technique	
  1	
  –	
  Constant	
  Result	
  
user.$(“getName”,	
  “Rose	
  Tyler”);	
  
	
  
//Technique	
  2	
  –	
  Rota)ng	
  Results	
  
user.$(“getName”).$results(“Rose	
  Tyler”,	
  “Amelia	
  Pond”,	
  “River	
  Song”);	
  
	
  
Using	
  $args()	
  
•  Results	
  based	
  on	
  the	
  Arguments	
  Passed	
  
•  Must	
  be	
  chained	
  via	
  Results.	
  
	
  
//	
  Call	
  to	
  Mock	
  
if(	
  dao.getSepng(“userAudit”)	
  ){	
  
startAudit(	
  dao.getSepng(“auditTables”)	
  );	
  
};	
  
	
  
//	
  Mocking	
  Calls	
  
dao.$(“getSepng”).$args(“userAudit”).$results(true);	
  
dao.$(“getSepng”).$args(“auditTables”).$results(“user,order,	
  
Using	
  $args()	
  
•  Arguments	
  are	
  smart	
  like	
  normal	
  func)ons	
  
–  Posi)onal	
  Arguments	
  
saveUser(”Rose”,”Tyler”);	
  
–  Named	
  Arguments	
  
saveUser(fname=”Rose”,lname=”Tyler”);	
  
–  Argument	
  Collec)ons	
  
data	
  =	
  {	
  
	
  fname	
  =	
  “Rose”,	
  lname	
  =	
  “Tyler”	
  
	
  };	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  saveUser(argumentCollec)on=data);	
  
	
  
$results()	
  
•  Your	
  results	
  can	
  be	
  	
  
–  Constant	
  
–  Or	
  Sequenced	
  
•  Your	
  results	
  will	
  loop	
  over	
  and	
  over.	
  
•  Argument	
  Based	
  Results	
  can	
  also	
  be	
  repe))ve	
  in	
  a	
  
sequence.	
  
$property()	
  
•  Mock	
  any	
  property	
  on	
  any	
  scope	
  
•  Great	
  for	
  sepngs	
  and	
  dependency	
  injec)on	
  mocking	
  
//	
  Mock	
  a	
  sepng	
  on	
  the	
  variables	
  scope	
  
service.$property(“cacheAc)ve”,”variables”,true);	
  
	
  
//	
  Mock	
  a	
  file	
  u)lity	
  object	
  
mockU)l	
  =	
  mockbox.createEmptyMock(“u)l.FileU)ls”);	
  
service.$property(“fileU)l”,”variables”,	
  mockU)l);	
  
	
  
//	
  Mock	
  in	
  the	
  variables.instance	
  scope	
  path	
  
service.$property(“isDirty”,”instance”,true);	
  
Verifica)on	
  Methods	
  
* Verification methods return boolean so they can be asserted
Verifica)on	
  Methods	
  
func)on	
  testVerifyCallCount(){	
  
	
  test.$("displayData",queryNew(''));	
  
	
  assertTrue(	
  test.$never()	
  );	
  
	
  assertTrue(	
  test.$never(“displayData”)	
  );	
  
	
  test.displayData();	
  
	
  assertFalse(	
  test.$)mes(1,”displayData”)	
  );	
  
	
  assertFalse(	
  test.$once(”displayData”)	
  );	
  
	
  test.displayData();	
  
	
  assertEquals(true,	
  test.$verifyCallCount(2));	
  
}	
  
Verifica)on	
  Methods	
  
	
  
func)on	
  testMockMethodCallCount(){	
  
	
  test.$("displayData",queryNew(''));	
  
	
  test.$("getLuis",1);	
  
	
  assertEquals(0,	
  test.$count("displayData")	
  );	
  
	
  assertEquals(-­‐1,	
  test.$count("displayData2")	
  );	
  
}	
  
Lets	
  look	
  at	
  a	
  Demo	
  
h6p://justmockit.local.com	
  
	
  
Code	
  available	
  at:	
  
h6ps://github.com/gpickin/justmockitdemo	
  
	
  
	
  
The	
  End	
  –	
  Thank	
  you	
  
•  Thanks	
  everyone	
  for	
  making	
  it	
  this	
  far	
  
•  All	
  of	
  the	
  materials	
  will	
  be	
  on	
  my	
  ITB	
  
presenta)on	
  Site:	
  	
  
h6p://www.gpickin.com/itb2014/	
  
•  Hit	
  me	
  up	
  on	
  twi6er	
  @gpickin	
  
•  Read	
  more	
  on	
  my	
  blog:	
  h6p://gpickin.com	
  
•  Check	
  out	
  my	
  CFO	
  Session	
  Thursday,	
  15th	
  
11:30am	
  –	
  12:30am	
  on	
  Lakes	
  Ballroom	
  C	
  

Weitere ähnliche Inhalte

Was ist angesagt?

Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingSteven Smith
 
Evil testers guide to technical testing
Evil testers guide to technical testingEvil testers guide to technical testing
Evil testers guide to technical testingAlan Richardson
 
AATC2016: Exploratory testing an API
AATC2016: Exploratory testing an APIAATC2016: Exploratory testing an API
AATC2016: Exploratory testing an APIMaaret Pyhäjärvi
 
TestWorksConf: Experience exploratory testing
TestWorksConf: Experience exploratory testingTestWorksConf: Experience exploratory testing
TestWorksConf: Experience exploratory testingMaaret Pyhäjärvi
 
Practical Test Automation Deep Dive
Practical Test Automation Deep DivePractical Test Automation Deep Dive
Practical Test Automation Deep DiveAlan Richardson
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing SoftwareSteven Smith
 
How to Improve Your Technical Test Ability - AADays 2015 Keynote
How to Improve Your Technical Test Ability - AADays 2015 KeynoteHow to Improve Your Technical Test Ability - AADays 2015 Keynote
How to Improve Your Technical Test Ability - AADays 2015 KeynoteAlan Richardson
 
If you want to automate, you learn to code
If you want to automate, you learn to codeIf you want to automate, you learn to code
If you want to automate, you learn to codeAlan Richardson
 
Automating Pragmatically - Testival 20190604
Automating Pragmatically - Testival 20190604Automating Pragmatically - Testival 20190604
Automating Pragmatically - Testival 20190604Alan Richardson
 
Automating to Augment Testing
Automating to Augment TestingAutomating to Augment Testing
Automating to Augment TestingAlan Richardson
 
Automating Strategically or Tactically when Testing
Automating Strategically or Tactically when TestingAutomating Strategically or Tactically when Testing
Automating Strategically or Tactically when TestingAlan Richardson
 
Technology Based Testing
Technology Based TestingTechnology Based Testing
Technology Based TestingAlan Richardson
 
Abstraction Layers Test Management Summit Faciliated Session 2014
Abstraction Layers Test Management Summit Faciliated Session 2014Abstraction Layers Test Management Summit Faciliated Session 2014
Abstraction Layers Test Management Summit Faciliated Session 2014Alan Richardson
 
Technical Testing Webinar
Technical Testing WebinarTechnical Testing Webinar
Technical Testing WebinarAlan Richardson
 
TestIstanbul May 2013 Keynote Experiences With Exploratory Testing
TestIstanbul May 2013 Keynote Experiences With Exploratory TestingTestIstanbul May 2013 Keynote Experiences With Exploratory Testing
TestIstanbul May 2013 Keynote Experiences With Exploratory TestingAlan Richardson
 
Black Ops Testing Workshop from Agile Testing Days 2014
Black Ops Testing Workshop from Agile Testing Days 2014Black Ops Testing Workshop from Agile Testing Days 2014
Black Ops Testing Workshop from Agile Testing Days 2014Alan Richardson
 
Automating Tactically vs Strategically SauceCon 2020
Automating Tactically vs Strategically SauceCon 2020Automating Tactically vs Strategically SauceCon 2020
Automating Tactically vs Strategically SauceCon 2020Alan Richardson
 
Test Bash Netherlands Alan Richardson "How to misuse 'Automation' for testing...
Test Bash Netherlands Alan Richardson "How to misuse 'Automation' for testing...Test Bash Netherlands Alan Richardson "How to misuse 'Automation' for testing...
Test Bash Netherlands Alan Richardson "How to misuse 'Automation' for testing...Alan Richardson
 

Was ist angesagt? (20)

Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Devfest 2019-slides
Devfest 2019-slidesDevfest 2019-slides
Devfest 2019-slides
 
Evil testers guide to technical testing
Evil testers guide to technical testingEvil testers guide to technical testing
Evil testers guide to technical testing
 
AATC2016: Exploratory testing an API
AATC2016: Exploratory testing an APIAATC2016: Exploratory testing an API
AATC2016: Exploratory testing an API
 
Low cost techniques for test doubles
Low cost techniques for test doublesLow cost techniques for test doubles
Low cost techniques for test doubles
 
TestWorksConf: Experience exploratory testing
TestWorksConf: Experience exploratory testingTestWorksConf: Experience exploratory testing
TestWorksConf: Experience exploratory testing
 
Practical Test Automation Deep Dive
Practical Test Automation Deep DivePractical Test Automation Deep Dive
Practical Test Automation Deep Dive
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
How to Improve Your Technical Test Ability - AADays 2015 Keynote
How to Improve Your Technical Test Ability - AADays 2015 KeynoteHow to Improve Your Technical Test Ability - AADays 2015 Keynote
How to Improve Your Technical Test Ability - AADays 2015 Keynote
 
If you want to automate, you learn to code
If you want to automate, you learn to codeIf you want to automate, you learn to code
If you want to automate, you learn to code
 
Automating Pragmatically - Testival 20190604
Automating Pragmatically - Testival 20190604Automating Pragmatically - Testival 20190604
Automating Pragmatically - Testival 20190604
 
Automating to Augment Testing
Automating to Augment TestingAutomating to Augment Testing
Automating to Augment Testing
 
Automating Strategically or Tactically when Testing
Automating Strategically or Tactically when TestingAutomating Strategically or Tactically when Testing
Automating Strategically or Tactically when Testing
 
Technology Based Testing
Technology Based TestingTechnology Based Testing
Technology Based Testing
 
Abstraction Layers Test Management Summit Faciliated Session 2014
Abstraction Layers Test Management Summit Faciliated Session 2014Abstraction Layers Test Management Summit Faciliated Session 2014
Abstraction Layers Test Management Summit Faciliated Session 2014
 
Technical Testing Webinar
Technical Testing WebinarTechnical Testing Webinar
Technical Testing Webinar
 
TestIstanbul May 2013 Keynote Experiences With Exploratory Testing
TestIstanbul May 2013 Keynote Experiences With Exploratory TestingTestIstanbul May 2013 Keynote Experiences With Exploratory Testing
TestIstanbul May 2013 Keynote Experiences With Exploratory Testing
 
Black Ops Testing Workshop from Agile Testing Days 2014
Black Ops Testing Workshop from Agile Testing Days 2014Black Ops Testing Workshop from Agile Testing Days 2014
Black Ops Testing Workshop from Agile Testing Days 2014
 
Automating Tactically vs Strategically SauceCon 2020
Automating Tactically vs Strategically SauceCon 2020Automating Tactically vs Strategically SauceCon 2020
Automating Tactically vs Strategically SauceCon 2020
 
Test Bash Netherlands Alan Richardson "How to misuse 'Automation' for testing...
Test Bash Netherlands Alan Richardson "How to misuse 'Automation' for testing...Test Bash Netherlands Alan Richardson "How to misuse 'Automation' for testing...
Test Bash Netherlands Alan Richardson "How to misuse 'Automation' for testing...
 

Ähnlich wie Just Mock It - Mocks and Stubs

CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!Ortus Solutions, Corp
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesTony Nguyen
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesHarry Potter
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesHoang Nguyen
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesYoung Alista
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesLuis Goldster
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesFraboni Ec
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesJames Wong
 
The Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To TestingThe Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To TestingTim Duckett
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctlyDror Helper
 
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...DevDay.org
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchMats Bryntse
 
Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...Niels Frydenholm
 
Junit, mockito, etc
Junit, mockito, etcJunit, mockito, etc
Junit, mockito, etcYaron Karni
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWHolger Grosse-Plankermann
 
Surviving javascript.pptx
Surviving javascript.pptxSurviving javascript.pptx
Surviving javascript.pptxTamas Rev
 
Unit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaUnit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaErick M'bwana
 

Ähnlich wie Just Mock It - Mocks and Stubs (20)

CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
The Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To TestingThe Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To Testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
 
Mock with Mockito
Mock with MockitoMock with Mockito
Mock with Mockito
 
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...
 
Easy mock
Easy mockEasy mock
Easy mock
 
Junit, mockito, etc
Junit, mockito, etcJunit, mockito, etc
Junit, mockito, etc
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
 
Surviving javascript.pptx
Surviving javascript.pptxSurviving javascript.pptx
Surviving javascript.pptx
 
Unit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaUnit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - Kenya
 

Mehr von Gavin Pickin

Itb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin PickinItb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin PickinGavin Pickin
 
Containerizing ContentBox CMS
Containerizing ContentBox CMSContainerizing ContentBox CMS
Containerizing ContentBox CMSGavin Pickin
 
ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 VueJS cod...
ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 VueJS cod...ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 VueJS cod...
ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 VueJS cod...Gavin Pickin
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEGavin Pickin
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION APIGavin Pickin
 
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....Gavin Pickin
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016Gavin Pickin
 
BDD Testing and Automating from the trenches - Presented at Into The Box June...
BDD Testing and Automating from the trenches - Presented at Into The Box June...BDD Testing and Automating from the trenches - Presented at Into The Box June...
BDD Testing and Automating from the trenches - Presented at Into The Box June...Gavin Pickin
 
How do I write Testable Javascript so I can Test my CF API on Server and Client
How do I write Testable Javascript so I can Test my CF API on Server and ClientHow do I write Testable Javascript so I can Test my CF API on Server and Client
How do I write Testable Javascript so I can Test my CF API on Server and ClientGavin Pickin
 
How do I write Testable Javascript?
How do I write Testable Javascript?How do I write Testable Javascript?
How do I write Testable Javascript?Gavin Pickin
 
Getting your Hooks into Cordova
Getting your Hooks into CordovaGetting your Hooks into Cordova
Getting your Hooks into CordovaGavin Pickin
 
Setting up your Multi Engine Environment - Apache Railo and ColdFusion
Setting up your Multi Engine Environment - Apache Railo and ColdFusionSetting up your Multi Engine Environment - Apache Railo and ColdFusion
Setting up your Multi Engine Environment - Apache Railo and ColdFusionGavin Pickin
 

Mehr von Gavin Pickin (12)

Itb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin PickinItb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin Pickin
 
Containerizing ContentBox CMS
Containerizing ContentBox CMSContainerizing ContentBox CMS
Containerizing ContentBox CMS
 
ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 VueJS cod...
ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 VueJS cod...ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 VueJS cod...
ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 VueJS cod...
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
 
BDD Testing and Automating from the trenches - Presented at Into The Box June...
BDD Testing and Automating from the trenches - Presented at Into The Box June...BDD Testing and Automating from the trenches - Presented at Into The Box June...
BDD Testing and Automating from the trenches - Presented at Into The Box June...
 
How do I write Testable Javascript so I can Test my CF API on Server and Client
How do I write Testable Javascript so I can Test my CF API on Server and ClientHow do I write Testable Javascript so I can Test my CF API on Server and Client
How do I write Testable Javascript so I can Test my CF API on Server and Client
 
How do I write Testable Javascript?
How do I write Testable Javascript?How do I write Testable Javascript?
How do I write Testable Javascript?
 
Getting your Hooks into Cordova
Getting your Hooks into CordovaGetting your Hooks into Cordova
Getting your Hooks into Cordova
 
Setting up your Multi Engine Environment - Apache Railo and ColdFusion
Setting up your Multi Engine Environment - Apache Railo and ColdFusionSetting up your Multi Engine Environment - Apache Railo and ColdFusion
Setting up your Multi Engine Environment - Apache Railo and ColdFusion
 

Kürzlich hochgeladen

VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Anthony Dahanne
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 

Kürzlich hochgeladen (20)

VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 

Just Mock It - Mocks and Stubs

  • 1. Just  Mock  It   Mocks  and  Stubs   Presented by Gavin Pickin Slides: http://gpickin.com/itb2014/ Website: http://gpickin.com Twitter: @gpickin
  • 2. Introduc)on   •  Follow  along  with  resources  from   h6p://gpickin.com/itb2014/     •  If  you  want  to  find  out  more  about  me,  my   website  has  more  than  enough  informa)on  
  • 3. 20  Second  Agenda   •  Unit  Tes)ng  -­‐  Recap   •  What  is  Mocking     •  What  is  a  Mock  /  Stub   •  Why  Mock   •  Let’s  look  at  some  Mocking  
  • 4. Unit  Tes)ng   “unit  tes)ng  is  a  soOware  verifica)on  and   valida)on  method  in  which  a  programmer  tests   if  individual  units  of  source  code  are  fit  for  use.   A  unit  is  the  smallest  testable  part  of  an   applica)on”   -­‐  wikipedia  
  • 5. Unit  Tes)ng   •  Can  improve  code  quality  -­‐>  quick  error   discovery   •  Code  confidence  via  immediate  verifica)on   •  Can  expose  high  coupling   •  Will  encourage  refactoring  to  produce  >   testable  code   •  Remember:  Tes)ng  is  all  about  behavior  and   expecta)ons  
  • 7. Bugs  Hurt   •  Bugs  hurt  –  the  later  in  the  process,  the   harder  to  fix.   •  Test  Early  and  OOen   – Find  them  before  they  rot  your  founda)on   •  Testable  Code  is  Maintainable  Code  
  • 10. Important  Tests   •  Unit  Tes)ng   – Test  behavior  of  individual  objects   •  Integra)on  Tes)ng   – Test  En)re  Applica)on  from  Top  Down   •  UI  verifica)on  tes)ng   – Verifica)on  via  HTML/Visual  elements  
  • 11. Important  Tes)ng  Tools   •  TestBox  (Run  BDD  and  MXUnit  style)   •  IDE  -­‐  CF  Builder  /  Eclipse   •  Mocking  Framework   •  ANT   •  Jenkins,  Bamboo,  Teamcity,  other  Cis   •  Selenium   •  Jmeter  or  Webstress  Tool,  Apache  AB    
  • 12. What  is  Mocking?   According  to  Merriam  Webster   •  to  laugh  at  or  make  fun  of  (someone  or   something)  especially  by  copying  an  ac)on  or   a  way  of  behaving  or  speaking   •  to  imitate  (as  a  mannerism)  closely    
  • 13. What  is  Mocking?   "A  mock  object  is  an  object  that  takes  the  place   of  a  ‘real’  object  in  such  a  way  that  makes   tes)ng  easier  and  more  meaningful,  or  in  some   cases,  possible  at  all"   by  Sco6  Bain  -­‐  Emergent  Design  
  • 18. Stub  Object   •  A  stub  is  an  empty  container,  that  represents   an  Object.   •  This  can  be  useful  for  represen)ng  CFCs  and   Objects  that  haven’t  been  wri6en  yet.  
  • 19. Why  use  Mocking   •  Isolate  your  SUT  -­‐>  SoOware  Under  Test   •  To  build  against  interfaces  &  contracts   •  Building  against  missing  integra)on  pieces   •  To  control  data  and  expecta)ons   •  Mock  components  whose  behavior  is   undesirable  or  hard  to  control  
  • 20. Why  Mock?   •  How  do  you  test  when  helper  components   that  are  not  built  yet?   •  How  do  you  do  controlled  excep)ons?   •  How  do  you  test  &  control  external  API  calls?   •  How  do  you  control  results  from  ColdFusion   tags  or  func)ons?   •  How  do  you  control  network  connec)ons?  Do   you  pull  the  network  plug?  
  • 21. Why  Mock?   How  do  you  test  code  like  this?     <cfdirectory  ac)on=”list”  directory=”#arguments.path#”  name=”qResults”>   <ck6p  url=”#arguments.urlPath#”  results=”qResults”>   <cfmail  to=”#to#”  from=”#from#”  subject=”#subject#”>#content#</cfmail>   <cfquery  />   func)on  init(){   var  helper  =  new  Helper();   }   private  func)on  getData(){  return  data;  }  
  • 22. The  COLD  hard  truth  –  It  can  Hurt   •  Tes)ng  some  code  is  hard,  or  almost   impossible.     •  Refactor  it   •  Mock  it   •  Test  It   •  With  CI,  you  can  forget  about  it    Un)l  it  breaks  
  • 23. Refactor  to  make  it  Mockable   •  Original:   <cfdirectory  ac)on=”list”  directory=”/myapp/path”  name=”qResults”>   •  Refactored   <cffunc)on  name=”getFiles”  output=”false”  returnType=”query”>          <cfargument  name=”path”>          <cfset  var  qResults  =  “”>          <cfdirectory  ac)on=”list”  directory=”#arguments.path#”  name=”qResults”>          ...  Process  Here  ...          <cfreturn  qResults>   </cffunc)on>  
  • 24. Normal  View  of  your  Service  
  • 25. Mock/Test  View  of  your  Service  
  • 26. What  do  we  Mock?   •  Excep)ons   •  Data   •  CFC  and  Objects   •  Methods  in  our  CFCs   •  Proper)es  in  our  CFCs  
  • 28. What  can  MockBox  do?   •  Mock  Objects  with  or  without  implementa)ons   •  Mock  methods  &  proper)es  in  any  scope   •  Create  Stub  Objects  -­‐>  Non-­‐existent  objects   •  Mock  excep)ons   •  Mock  arguments  to  results   •  Logging  &  Debugging   •  Verifica)on  methods   •  State  Machine  Results  
  • 29. Sepng  up  MockBox   •  Standalone  Version  (FW/1,  Fusebox,  Model   Glue,  Home  Brewed)   mockBox  =   createObject(“component”,”mockBox.system.tes)ng.MockBox”).init();     •  Running  from  inside  ColdBox  (outside  of  TestBox)   mockBox  =   createObject(“component”,”coldbox.system.tes)ng.MockBox”).init();  
  • 30. Using  MockBox   •  MockBox  does  its  magic  dynamically,  adding  /   decora)ng  CFCs  with  necessary  methods.     •  CreateMock()   user  =  mockBox.createMock(“model.User”);   •  CreateEmptyMock()   dao  =  mockBox.createEmptyMock(“model.UserDAO”);   •  PrepareMock()   mockBox.prepareMock(  service  );  
  • 31. Using  MockBox  -­‐  Stubs   •  CreateStub()   –  Create  a  simple  empty  Stub   –  Pass  an  Implements  to  get  a  Mock  Interface   –  Pass  an  Extends  to  get  a  Mock  with  Inheritance     nonExistentService  =  mockBox.createStub();   mockInterface  =  mockBox.createStub(implements=”model.ICache”);   mockInheritance  =  mockbox.createStub(extends=”model.SecurityService”);  
  • 33. $()   •  Argument   –  method   –  returns   –  preserveReturnType   –  throwExcep)on   –  throwType   –  throwDetail   –  throwMessage   –  callLogging   // Cascaded mocks mockUser.$(“isFound”,true).$(“isDirty”,true); // Mock Exception mockUser. $(method=”save”, throwsException=true, throwType=”IllegalStateException”, throwMessage=”Invalid User Data”); // Mock Return Objects mockRole = mockBox.createMock(“Role”); service.$ (method=”getRole”,returns=mockRole);
  • 34. Using  $()   mockUser  =  mockBox.createEmptyMock(“model.User”).init();   userService  =  mockBox.createMock(“model.UserService”).init();   user  =  userService.$(“get”,  mockUser);     //Technique  1  –  Constant  Result   user.$(“getName”,  “Rose  Tyler”);     //Technique  2  –  Rota)ng  Results   user.$(“getName”).$results(“Rose  Tyler”,  “Amelia  Pond”,  “River  Song”);    
  • 35. Using  $args()   •  Results  based  on  the  Arguments  Passed   •  Must  be  chained  via  Results.     //  Call  to  Mock   if(  dao.getSepng(“userAudit”)  ){   startAudit(  dao.getSepng(“auditTables”)  );   };     //  Mocking  Calls   dao.$(“getSepng”).$args(“userAudit”).$results(true);   dao.$(“getSepng”).$args(“auditTables”).$results(“user,order,  
  • 36. Using  $args()   •  Arguments  are  smart  like  normal  func)ons   –  Posi)onal  Arguments   saveUser(”Rose”,”Tyler”);   –  Named  Arguments   saveUser(fname=”Rose”,lname=”Tyler”);   –  Argument  Collec)ons   data  =  {    fname  =  “Rose”,  lname  =  “Tyler”    };                        saveUser(argumentCollec)on=data);    
  • 37. $results()   •  Your  results  can  be     –  Constant   –  Or  Sequenced   •  Your  results  will  loop  over  and  over.   •  Argument  Based  Results  can  also  be  repe))ve  in  a   sequence.  
  • 38. $property()   •  Mock  any  property  on  any  scope   •  Great  for  sepngs  and  dependency  injec)on  mocking   //  Mock  a  sepng  on  the  variables  scope   service.$property(“cacheAc)ve”,”variables”,true);     //  Mock  a  file  u)lity  object   mockU)l  =  mockbox.createEmptyMock(“u)l.FileU)ls”);   service.$property(“fileU)l”,”variables”,  mockU)l);     //  Mock  in  the  variables.instance  scope  path   service.$property(“isDirty”,”instance”,true);  
  • 39. Verifica)on  Methods   * Verification methods return boolean so they can be asserted
  • 40. Verifica)on  Methods   func)on  testVerifyCallCount(){    test.$("displayData",queryNew(''));    assertTrue(  test.$never()  );    assertTrue(  test.$never(“displayData”)  );    test.displayData();    assertFalse(  test.$)mes(1,”displayData”)  );    assertFalse(  test.$once(”displayData”)  );    test.displayData();    assertEquals(true,  test.$verifyCallCount(2));   }  
  • 41. Verifica)on  Methods     func)on  testMockMethodCallCount(){    test.$("displayData",queryNew(''));    test.$("getLuis",1);    assertEquals(0,  test.$count("displayData")  );    assertEquals(-­‐1,  test.$count("displayData2")  );   }  
  • 42. Lets  look  at  a  Demo   h6p://justmockit.local.com     Code  available  at:   h6ps://github.com/gpickin/justmockitdemo      
  • 43. The  End  –  Thank  you   •  Thanks  everyone  for  making  it  this  far   •  All  of  the  materials  will  be  on  my  ITB   presenta)on  Site:     h6p://www.gpickin.com/itb2014/   •  Hit  me  up  on  twi6er  @gpickin   •  Read  more  on  my  blog:  h6p://gpickin.com   •  Check  out  my  CFO  Session  Thursday,  15th   11:30am  –  12:30am  on  Lakes  Ballroom  C