Top Banner
Becoming a better PROGRAMMER Unit Tes)ng
19

Becoming a better programmer - unit testing

Jul 17, 2015

Download

Software

Duy Tan Geek
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Becoming a better programmer - unit testing

Becoming a better PROGRAMMER

Unit  Tes)ng  

Page 2: Becoming a better programmer - unit testing

About my company:

•  Founded: Oct/2003 •  Headquarter: Tokyo •  Services: Web & Smartphone

development •  Number of employees: 60 SeeSaa  

Tokyo  

Viet  Nam  

Kyoto  

Page 3: Becoming a better programmer - unit testing

Web services:

Page 4: Becoming a better programmer - unit testing

Smartphone apps:

Page 5: Becoming a better programmer - unit testing

About me:

Nguyen  The  Cuong  

Android  Developer  

im.thecuong  

HUT  

Page 6: Becoming a better programmer - unit testing

Agenda: What  is  Unit  Test  ?  

Why  should  we  do  Unit  Test  ?  

When,  Where  &  Who  do  Unit  Test  ?  

How  to  write  a  good  Unit  Test  

Page 7: Becoming a better programmer - unit testing

Development process

Page 8: Becoming a better programmer - unit testing

Test Driven Development

Page 9: Becoming a better programmer - unit testing

Unit Test

Unit  Tes)ng  is  a  process  of  wri)ng  test  for  specific  part  of  code/system.      

A  Unit  is  the  smallest  possible  part  of  

applica)on/system  under  test.  

Tes)ng  is  a  process  of  

 checking/evalua)ng  an  aJribute/characteris)cs/

capability  of  a  method/object/program…    

and  determining  that  actual  behavior  meets  with  expected  

behavior.  

Page 10: Becoming a better programmer - unit testing

Why should we do Unit Test ?

•  How  about  Logger,  Debugger  ?  

Faster  debugging,  isn’t  it  ?  

•  Not  sure,  even  slower!  Faster  development,  isn’t  it  ?  

•  Let  see  an  example:  

Faster  tes)ng  ?  

Page 11: Becoming a better programmer - unit testing

Example Testing max of list keyword ?

Page 12: Becoming a better programmer - unit testing

Why should we do Unit Test ?

•  Instead  of  wri)ng  code  to  do  something,  you’re  star)ng  by  outlining  all  the  condi)ons  you’re  subjec)ng  the  code  to  and  what  outputs  you’d  expect  from  that  

Designing  soUware  components  robustly  

•  Avoid  regression  errors  •  You  test  the  code  once  and  the  con)nuously  aUerwards  •  For  people  who  are  going  to  maintain  or  develop  your  code  

Reduce  future  code  

Page 13: Becoming a better programmer - unit testing

• Of  course,  are  developers  

Who  create  Unit  Test  ?    

• Right  aUer  get  &  read  details  design/requirement.  

Where  in  project  development  ?  

Page 14: Becoming a better programmer - unit testing

• Depends  on  size  of  the  project  ?  • Depends  on  kind  of  the  project  ?  • Depends  on  level  of  the  developer  ?  

When  do,  when  don’t  ?  

Page 15: Becoming a better programmer - unit testing

•  Process: •  Get & Read detail design document •  Choose a function to develop, then follow

to the diagram •  Take attention: whenever refactoring your

code, you should run unit test accordingly. Along with adding new code, you need to perform corresponding tests as well.

How to write a good Unit Test

Page 16: Becoming a better programmer - unit testing

Structure: •  Set up all conditions for testing •  Call the method (or trigger)

being tested •  Verify that the result is correct •  Teardown: clean up modified

records

How to write a good Unit Test

Page 17: Becoming a better programmer - unit testing

Some tips: •  Make each test independent to all the

others •  Test one thing only in one test case •  One function may have multiple unit

tests according to the usage and outputs of the function

•  Don’t forget to refactor the test code •  With little time and much to test you can’t

afford lengthy and ineffective checks. Make test case simple, concentrate on the core behavior of your product and use as little code as you can.

•  Creating maintainable & readable tests

How to write a good Unit Test

Page 18: Becoming a better programmer - unit testing

Conclusion Without doubt, unit testing can significantly increase the quality of your project

Page 19: Becoming a better programmer - unit testing