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.

When you get lost in api testing #ForumPHP

If you are not writing tests yet, you should start. Tests will improve the quality of your code, reduce bugs and probably force you to think more about design and quality. Actually, the hardest thing is to start and figure out which type of tests to write.

So you start researching and you find a lot of different materials and get even more confused.Even when you decide what type of tests to use, it can be hard to decide how to test some specific logic in your app.

Don’t give up! We have some tips we learned along the way that will hopefully make your life easier. In this talk you will hear about different test types and when to use them. We’ll also show some tools for checking quality of your test.

  • Login to see the comments

  • Be the first to like this

When you get lost in api testing #ForumPHP

  1. 1. WHEN YOU GET LOST IN API TESTING Paula Čučuk & Antonio Perić - Mažar
  2. 2. About us Paula Antonio paula@locastic.com antonio@locastic.com @paulala_14 @antonioperic CEO @ LocasticBackend developer @ Locastic
  3. 3. Locastic Helping clients create web and mobile apps since 2011 • UX/UI • Mobile apps • Web apps • Training & Consulting www.locastic.com @locastic
  4. 4. What happens when you don’t write tests?
  5. 5. Destroyed 293 seconds after liftoff because of one wrong character in formula $135 million lost!
  6. 6. Not a rocket developer?
  7. 7. Writing tests benefits Reducing the number of bugs Improving code quality Easier and faster refactoring Time saving Use-case based documentation
  8. 8. The test pyramid
  9. 9. Unit tests Unit testing is a level of testing where individual units/components are tested. The purpose is to validate that each separate unit performs as expected. A unit is the smallest testable part of any software.
  10. 10. It’s not unit tests, it’s you! Refactor your code using SOLID principles.
  11. 11. Are unit tests enough?
  12. 12. Integration tests Integration testing is the phase in software testing in which individual software modules are combined and tested as a group.
  13. 13. When to use integration tests Validation 3rd party integration Database queries Verifying two or more modules which have unit tests work as expected together
  14. 14. Functional tests Functional testing is defined as the testing of complete functionality of some application.
  15. 15. Functional tests In each functional tests check: Response code Response header Response content: contains expected fields in expected format
  16. 16. Functional tests Test that each endpoint behaves as expected for: OK request and response Bad request and Validation response Forbidden access response
  17. 17. Let’s test puzzles!
  18. 18. Unit tests Assert it has image Assert it has puzzle shape Assert it can be moved Assert it can be merged
  19. 19. Integration tests Assert two puzzles fit ok together by shape and image
  20. 20. Integration tests Assert it throws an exception when combining two puzzles that don’t fit together by shape
  21. 21. Integration tests Assert it throws an exception when combining two puzzles that fit together by shape but don’t fit by image
  22. 22. Functional tests Assert it returns OK response Assert it has correct headers
  23. 23. Functional tests Assert it returns bad request response Assert it has correct headers
  24. 24. What we learned along the way
  25. 25. Do I need to write tests first? It’s just one of the approaches
  26. 26. Do I need to have 100% coverage? 100% coverage doesn’t guarantee your code is fully tested and working
  27. 27. What about legacy code? 1. Start replicating bugs with tests before fixing them 2. Test at least most important and critical parts
  28. 28. How do I test some specific code? Check out the tests of the libraries and framework you are using
  29. 29. How do I know if the tests I wrote are good enough? Ask yourself: “Am I sure the code I tested works as it should?”
  30. 30. Tools for checking test quality
  31. 31. Infection Tool for mutation testing in PHP
  32. 32. PHP Stan PHP Static Analysis Tool
  33. 33. Continuous integration (CI) Tool for tuning tests on GIT
  34. 34. Handy testing tools
  35. 35. The test Http Client in API Platform Created for PHPUnit Manipulates the Symfony HttpKernel directly to simulate HTTP requests and responses Huge performance boost compared to triggering real network requests
  36. 36. The test Http Client in API Platform
  37. 37. PHP Matcher Library that enables you to check your response against patterns.
  38. 38. PHP Matcher Library that enables you to check your response against patterns.
  39. 39. Faker Library for generating random data
  40. 40. Postman tests
  41. 41. Postman tests + Newman Run and test a Postman Collection directly from the command line
  42. 42. Conclusion • You should write tests! • It’s important to write Unit, Integration and Functional tests • If something is hard to test - refactor it • Check out the tools we mentioned
  43. 43. Thank you!
  44. 44. Questions? Paula Antonio paula@locastic.com antonio@locastic.com @paulala_14 @antonioperic CEO @ LocasticBackend developer @ Locastic

×