Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

[DevDay2018] Unit testing in PHP and Laravel Framework - Unit testing in PHP and Laravel Framework

105 views

Published on

With this session, our speaker will take you through:
– The importance of wring code to testing your code
– Introduction on unit testing and some other testing methods
– How to write unit test
– Code coverage
– Mock and stub
– Apply with PHP and Laravel framework

Published in: Technology
  • Be the first to comment

  • Be the first to like this

[DevDay2018] Unit testing in PHP and Laravel Framework - Unit testing in PHP and Laravel Framework

  1. 1. U N I T T E S T I N G I N P H P A N D L A R A V E L F R A M E W O R K
  2. 2. ‣ LE MAI VIEN ‣ 28 years old ‣ Asian Tech Inc. ‣ Technical Leader ‣ Backend developer ‣ 5 years of experiences A B O U T M E
  3. 3. W H A T I S H I G H Q U A L I T Y C O D E ? ? ? I T ’ S G O O D ? ? ?
  4. 4. W H A T I S H I G H Q U A L I T Y C O D E ? ? ? S E L F E XP L A I N I N G D O C U M E N T A T I O N C L E A R - R E A D A B L E A R C H I T E C T U R E D E S I G N D E S I G N P A T T E R N T E S T C O D E E A S E O F E XT E N S I B I L I T Y
  5. 5. ‣ Test by human ‣ Create test cases ‣ Repeat many times ‣ Difficult to check affection ‣ Take a lot of time and efforts M A N U A L T E S T I N G
  6. 6. W H A T D O D E V E L O P E R S D O W H E N T H E Y I M P L E M E N T C O D E T E S T Switch
  7. 7. Y O U A L R E A D Y T E S T Y O U R C O D E S U B M I T A F O R M , C H E C K D B C O N S O L E . L O G ( ) D U M P V A R I A B L E S L O G T O F I L E C H R O M E D E B U G T O O L …
  8. 8. W R I T E C O D E T O T E S T Y O U R C O D E ‣ Check code by code ‣ Can reuse many time ‣ There are many kinds of test code W H Y N O T ?
  9. 9. T E S T I N G M E T H O D S ‣ Unit testing ‣ Integration testing ‣ Functional testing ‣ Acceptance testing ‣ E2E testing
  10. 10. W H Y D E V E L O P E R H A V E T O W R I T E C O D E T O T E S T T H E I R C O D E ‣ Quality of code ‣ Find bugs early ‣ Facilitates changes simplifies integration ‣ Provide document ‣ Debugging process ‣ Design ‣ Reduce cost
  11. 11. U N I T T E S T I N G ‣ Test a smallest piece of testable code ‣ Check the Code is working as expected ‣ Testing in isolation ‣ Tests should not be order-dependent
  12. 12. U N I T T E S T I N G Unit tests Production code
  13. 13. 3 steps of a Unit test 1. Arrange 2. Act 3. Assert
  14. 14. 1 0 0 1 R E A S O N S T O S K I P U N I T T E S T ‣ I don’t have time ‣ Deadline is too short ‣ I don’t know how to do ‣ Client doesn’t want to write UT ‣ … A L L J U S T E X C U S E , L E T W R I T E U N I T T E S T
  15. 15. U N I T T E S T I S I M P O R T A N T , I S N ’ T I T ?
  16. 16. C O D E C O V E R A G E
  17. 17. T e s t e d T e s t e d
  18. 18. C r e a t e m o c k o b j e c t M O C K E R Y ple yet flexible PHP mock object framework for use in unit te
  19. 19. S E T E X P E C T A T I O N S T O M O C K O B J E C T T h i s m e t h o d m u s t b e c a l l e d e x a c t l y 1 t i m e
  20. 20. Mock vs Stub Setup Exercise Verify state Teardown Setup data Setup Expectations Exercise Verify expectations Verify state Teardown
  21. 21. U N I T T E S T I N G ‣ Test a smallest piece of code ‣ Testing in isolation ‣ Code coverage ‣ Stub and mock
  22. 22. H O W A B O U T L A R A V E L ?
  23. 23. I t ’ s n o t u n i t t e s t i n g I t ’ s f u n c t i o n a l t e s t i n g L A R A V E L H T T P T E S T
  24. 24. L A R A V E L T E S T J S O N A P I
  25. 25. S U M M A R Y ‣ Manual test ‣ Benefit of writing code to test your code ‣ Phpunit ‣ Unit testing ‣ Code coverage ‣ Another testing methods
  26. 26. T H A N K Y O U F O R L I S T E N I N G http://asiantech.vn/en/careers

×