Raphael Almeida - Mocks, Stubs, Fakes, Dummies e Spies

Raphael Almeida - Mocks, Stubs, Fakes, Dummies e Spies

Aprenda a tornar seus testes mais simples, rápidos e enxutos com a sutilização de mocks, stubs, fakes, dummies e spies.

184d32a034c53d328bf523c7b2ef1197?s=128

Agile Testers

April 08, 2017
Tweet

Transcript

  1. Mocks, Stubs, Fakes Dummies and Spies Raphael Almeida

  2. Who Am I? Raphael Almeida Developer since 2006 Co-founder of

    PHPRio, DojoRio, RubyOnRio … Community-a-holic
  3. Double Objects Type of Verifications Best Practices

  4. Double Objects: Simplist test

  5. Double Objects: Awkward test

  6. Double Objects: Types Dummies Fakes Stubs Spies Mocks

  7. Dummies Used whenever we need to pass irrelevant or never

    used arguments only to respect the method signature
  8. Dummies

  9. Fakes Simplified implementation of a real method

  10. Fakes

  11. Stubs Provide canned responses to calls made during the test

  12. Stubs

  13. Spies Stubs that also record some information based on how

    they were called
  14. Spies

  15. Mocks Pre-programmed objects with expectations which form a specification of

    the calls they are expected to receive
  16. Mocks

  17. Double Objects Type of Verifications Best Practices

  18. Types of Verifications State or Behaviour

  19. Verifying State We inspect the state of the tested object

    after it has been exercised and compare it to the expected state
  20. Verifying Behaviour We capture the indirect output of the tested

    object as they occur and compare them to the expected behavior
  21. Double Objects Type of Verifications Best Practices

  22. Best Practices Don’t mock values Verify the context (easy or

    awkward) Use Fixtures with parsimony Coupling test to implementations
  23. References https://martinfowler.com/articles/mocksArentStubs.html https://github.com/padraic/mockery https://github.com/php-vcr/php-vcr XUnit Test Patterns - the book

  24. Thank you Raphael Almeida @raph_almeida