$30 off During Our Annual Pro Sale. View Details »

Tuenti <3 Testing

Tuenti
June 01, 2015

Tuenti <3 Testing

Story of a healthy addiction

Tuenti

June 01, 2015
Tweet

More Decks by Tuenti

Other Decks in Programming

Transcript

  1. Joaquin Engelmo
    [email protected]
    Tuenti <3 Testing
    (Story of a healthy addiction)

    View Slide

  2. View Slide

  3. View Slide

  4. esting
    T

    View Slide

  5. • We <3 our customers
    • Confidence
    • Safety Net
    • Refactoring, refactoring, refactoring
    • It is professional, guys :)

    View Slide

  6. http://lisacrispin.com/2011/11/08/using-the-agile-testing-quadrants/

    View Slide

  7. By Martin Fowler
    http://martinfowler.com/bliki/TestPyramid.html

    View Slide

  8. • Black-box oriented tests
    • End to end
    • Web/phone/simulator
    • No tests doubles can be used
    • Needs a full and provisionable
    server environment
    • Slow tests
    Acceptance Tests
    Concepts

    View Slide

  9. Acceptance Tests
    Environment
    KIF

    View Slide

  10. • JVM/PHP/Whatever
    • No need external env set up
    • Tests run in build time
    • Use test doubles
    • Slower tests than unit tests
    Integration Tests
    Concepts

    View Slide

  11. Integration Tests
    Environment

    View Slide

  12. • JVM/PHP/Whatever
    • Application classes in isolation
    • Test doubles
    • Build time
    • Really fast tests
    Unit Tests
    Concepts

    View Slide

  13. Unit Tests
    Environment
    • Fast
    • Isolated
    • Repeatable
    • Self-Verifing
    • Timely

    View Slide

  14. Doubles
    • Stubs => Canned answers
    • Mocks => Stubs + verify
    • Spies => Record interaction info
    • Fake => I seem real but not
    • Dummy => I do nothing at all

    View Slide

  15. What’s wrong with this?

    View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. Testability
    • Mixing object graph construction
    with application logic
    • Ask for things, don’t look for things
    • Doing work in constructor
    • Global State/Singletons
    • Static methods

    View Slide

  20. Talk is cheap.
    Show me the code.

    View Slide

  21. Testability
    Mixing object graph construction with application logic
    • Factories, these are full of the "new" operators and
    are responsible for building the object graph of the
    application, but don't do anything else.
    • Business logic classes, which are devoid of the
    "new" operator and are responsible for doing work.

    View Slide

  22. Testability
    Mixing object graph construction with application logic

    View Slide

  23. Testability
    Mixing object graph construction with application logic

    View Slide

  24. Testability
    Mixing object graph construction with application logic

    View Slide

  25. Testability
    Ask for things, don’t look for things
    • Just ask for all of the collaborators you need in your
    constructor.
    • But, if you find yourself needing to pass 10
    collaborators to your constructor, maybe it's time to
    step back and think about the design

    View Slide

  26. Testability
    Doing work in constructor
    • Any work you do in a constructor, you will have to
    successfully navigate through on every instantiation
    • There's no way to mock or handle work inside
    constructor. (actually there’s but you don’t wanna do it)
    • Do as little work in constructor as possible
    (Ideally just assigning passed parameters to the
    instance variables).

    View Slide

  27. Testability
    Doing work in constructor

    View Slide

  28. Testability
    Doing work in constructor

    View Slide

  29. Testability
    Doing work in constructor

    View Slide

  30. Testability
    Doing work in constructor

    View Slide

  31. View Slide

  32. View Slide

  33. Testability
    Global State
    • Global State from the testing point of view is a real problem.
    • When tests modify global state, next run tests will be affected by
    this modification, this means that the order of the tests execution
    matters in this case.
    • Some tests can pass in isolation, but not when running them
    together.
    • Not sure about the current state of the global object.
    • Really hard to debug.
    • Tests cannot run in parallel.

    View Slide

  34. Testability
    Singletons
    • Are global state in sheep’s clothing.
    • All of the internal objects of the singleton are global
    as well.
    • The core of the issue is that the global instance
    variables have transitive property!

    View Slide

  35. Testability
    Static Methods
    • Procedural code has no seams (places where you can divert the
    normal execution flow)
    • How much a static method will hurt from a testing point of view
    depends on where it is in the application call graph. A leaf method
    such as Math.abs() is not a problem. But it could stop being a leaf
    in any moment when functionality needs to be changed.

    View Slide

  36. Testability
    Global State & Singletons & Static Methods

    View Slide

  37. Testability
    Global State & Singletons & Static Methods

    View Slide

  38. Testability
    Global State & Singletons & Static Methods

    View Slide

  39. rchitecture
    A

    View Slide

  40. What are we going to use?
    • Clean Architecture
    • Microservices
    • S.O.L.I.D
    • Dependency Injection

    View Slide

  41. Did you said
    ‘Clean’?

    View Slide

  42. Uncle Bob
    Clean
    https://www.youtube.com/watch?v=WpkDN78P884
    http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html

    View Slide

  43. Did you said
    ’SOLID’ too?

    View Slide

  44. Uncle Bob
    S.O.L.I.D.
    http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
    • Single Responsibility
    • Open-Close
    • Liskov Substitution
    • Interface Segregation
    • Dependency Inversion

    View Slide

  45. Thanks!

    View Slide