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.

PChomePay unit test basic

48 views

Published on

This slide is about the basic unit test concept of internal training series.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

PChomePay unit test basic

  1. 1. Unit Test example by PHPUnit Eric G 2019
  2. 2. What is a unit test ? A unit test is a piece of code that invokes a unit of work and checks one specific end result of that unit of work. If the assumptions on the end result turn out to be wrong, the unit test has failed. A unit test’s scope can span as little as a method or as much as multiple classes.
  3. 3. How you test right now ? AuthService
 .login {
 …
 }
  4. 4. What are problems in previous case?
  5. 5. • It’s considered an integration test • It’s redundant for many test cases • Must test every cases after modifying the code in the same unit • Other team members don’t know how to test it
  6. 6. What makes a good unit test • It should be automated and repeatable • It should be easy to implement • It should be relevant tomorrow • Anyone should be able to run it at the push of a button • It should be run quickly • It should be consistent in its results (it always returns the same result if you don’t change anything between runs) • It should have full control of the unit under test • It should be fully isolated (runs independently of other tests) • When it fails, it should be easy to detect what was expected and determine how to pinpoint the problem Art of unit testing 2nd(1.2 Properties of a good unit test). Roy Osherove
  7. 7. Writing the first unit test
  8. 8. Demo Writing the first test
  9. 9. Unit test framework PHPUnit
  10. 10. Why we want to use unites framework • It can be automated and repeatable • It can be easy to implement • It can be relevant tomorrow • Anyone can be able to run it at the push of a button • It can be run quickly • It should be consistent in its results (it always returns the same result if you don’t change anything between runs) • It can have full control of the unit under test • It can be fully isolated (runs independently of other tests) • When it fails, it should be easy to detect what was expected and determine how to pinpoint the problem
  11. 11. Setting PHPUnit in PHPStorm
  12. 12. Demo
  13. 13. Types of assertions • Return value • State changing • Object Interaction
  14. 14. Important rules in unit test • AAA(Got When Then) pattern • Test naming • Single Assertion
  15. 15. Setup & Teardown Art of unit testing 2nd(Figure 2.5 How NUnit calls SetUp and TearDown). Roy Osherove
  16. 16. Demo

×