Slide 1

Slide 1 text

John  Mertic   Rate  this  talk  at  https://joind.in/6293  

Slide 2

Slide 2 text

¡  John  Mertic   §  Contact  Info   ▪  http:// jmertic.wordpress.com   ▪  Twitter:  @jmertic   §  Community  Manager  for   SugarCRM   ▪  http://www.sugarcrm.com   ▪  http://bit.ly/SugarDevBlog   ▪  Twitter:  @sugarcrmdev   ▪  [email protected]    

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

THE  GOOD  PART   ¡  Code  is  established,  known   working   ¡  Functionality  is  well  vetted   by  the  stakeholders   ¡  End  users  are  well  trained   and  versed  it  using  it   AND  THE  BAD   ¡  Code  can  be  very   “patchwork”  like,  many   different  hands  over  time   ¡  Functionality  may  not   match  today’s  needs   ¡  End  users  work  with  the   system  versus  the  system   working  with  them  

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

FUNCTIONAL   ¡  Tests  the  code  indirectly     from  the  user  perspective   ¡  Tests  how  several   components  work  together   ¡  Can  be  easier  to  get  going   on  a  legacy  codebase   UNIT   ¡  Tests  the  code  directly   from  the  developer   perspective   ¡  Tests  individual   components  specifically   ¡  Tends  to  be  more   challenging  to  get  going  on   a  legacy  codebase  

Slide 18

Slide 18 text

¡  Procedural  code   ¡  Poorly  designed  objects   §  Static  dependencies   §  Busy  constructors   §  Really  looooooooooong  methods   §  A  bizarre  affection  for  the  global  scope  

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

¡  Procedural  code;  weigh  the  viability  of  a  unit   versus  functional  test   ¡  Build  helper  functions/classes/tools  to  do   repetitive  work  for  you.   ¡  Make  a  practice  of  resetting  the  global  scope   §  PHPUnit  can  do  this  for  you   ¡  Keep  focused  on  the  primary  goal  of  your   tests.  

Slide 24

Slide 24 text

id; return $user_ids; } }

Slide 25

Slide 25 text

retrieve('1'); } function tearDown() { } ---CLIPPED--- }

Slide 26

Slide 26 text

Slide 27

Slide 27 text

should_process) { return ''; } $str = ''; if ($this->multiSelect == true && $this->show_mass_update_form) { $str = $this->mass->getDisplayMassUpdateForm(true, $this->multi_select_popup). $this->mass->getMassUpdateFormHeader($this->multi_select_popup); } return $str; } --clipped code section— }

Slide 28

Slide 28 text

_lvd = new ListViewDisplay; } public function testDisplayIfShowMassUpdateFormTrueAndMultiSelectTrue() { $this->_lvd->should_process = true; $this->_lvd->show_mass_update_form = true; $this->_lvd->multiSelect = true; $this->_lvd->multi_select_popup = true; $this->_lvd->mass = $this->getMock('MassUpdate'); $this->_lvd->mass->expects($this->any()) ->method('getDisplayMassUpdateForm') ->will($this->returnValue('foo')); $this->_lvd->mass->expects($this->any()) ->method('getMassUpdateFormHeader') ->will($this->returnValue('bar')); $this->assertEquals('foobar',$this->_lvd->display()); } }

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

¡  Write  a  unit  test  as  part  of  each  bug  you  fix.   ¡  Learn  lessons  from  each  test  you  write   §  How  difficult  was  it  to  isolate  the  issue?   §  How  much  scaffolding  had  to  be  done  to  do  the   tests?   §  What  tools/techniques  would  make  testing  easier?  

Slide 31

Slide 31 text

¡  Find  ways  to  make  writing  the  tests  easier   §  Add  helpers  or  toolkits  to  use   §  Build  testing  templates   §  Build  example  tests  people  can  copy  from.   ¡  Expand  testing  to  full  components   §  Idea:  create  a  policy  that  if  you  add  a  unit  test  for   a  function/method,  you  should  make  sure  you  add   full  coverage  for  the  function/method  and  not  just   for  the  bug  itself  

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

¡  It  takes  too  much  time   ¡  It’s  too  hard  to  test  a   certain  piece  of  code   ¡  I’ll  never  get  100%   code  coverage,  so  why   bother   ¡  I  can’t  justify  the  cost/ value  of  it   ¡  So  does  fixing  the   same  bug  over  and   over   ¡  Develop  a  better   strategy  for  testing   ¡  Nobody  has  100%  code   coverage   ¡  Adding  a  test  now   helps  prevent  the   problem  from  re-­‐ occurring  

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

assertEqual($this- >_mod_strings[$label_name], $this- >_mod_strings['LBL_CURRENCY']); } }

Slide 36

Slide 36 text

¡  Are  the  right  type  (  unit  vs  functional  )   ¡  Isolate  and  cover  the  issue   ¡  Fail  if  the  fix  isn’t  in  place;  pass  if  it  is   ¡  Sensible  to  debug  

Slide 37

Slide 37 text

¡  Elegant   ¡  High  performance   ¡  Hold  to  some  ideology  

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

¡  Things  change   ¡  New  shiny  things  make  things  easier   ¡  Pressure   ¡  Cluelessness  

Slide 43

Slide 43 text

¡  Learn  from  mistakes   ¡  Embrace  pragmatism   ¡  Don’t  be  ignorant   ¡  Ask  for  help!  

Slide 44

Slide 44 text

Rate  this  talk  at  https://joind.in/6293