Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Love your tests

129b5ff44f5d43b6e7cf6703211abe7e?s=47 Tuenti
November 27, 2015

Love your tests

Testing practices and principles used at .Tuenti in order to get better tests and make them easier to write and read.

129b5ff44f5d43b6e7cf6703211abe7e?s=128

Tuenti

November 27, 2015
Tweet

Transcript

  1. Love your tests @KINISOFTWARE MADRID · NOV 27-28 · 2015

  2. .Love your tests (Story of a healthy addiction - Chapter

    2) kinisoftware kini@tuenti.com
  3. None
  4. None
  5. We are hiring!!

  6. Once upon a time… 2013 1

  7. .Tuenti <3 .Testing (Story of a healthy addiction - Chapter

    1)
  8. • We <3 our customers • Confidence • Safety Net

    • Refactoring, refactoring, refactoring • It is professional, guys :)
  9. By Martin Fowler

  10. Testability

  11. Present day… 2

  12. Good good

  13. “It’s overwhelmingly easy to write bad unit tests that add

    very little value to a project while inflating the cost of code changes astronomically.”
  14. • Code coverage != Test quality • Don’t Repeat Yourself

    (Globally) • Mocks, mocks everywhere • Test smells
  15. .Tuenti Subject Under Test 3

  16. Microservices Fresh start Java Focus on testability

  17. Talk is cheap. Show me the code.

  18. Coding time (1446 tests) •Code readability + Naming + Code

    structure + DSL • One (logical) assert per test + Meaningful asserts + Custom matchers • Exceptions • Builders + Mothers • Mock providers • Testing real things • Customize your runners + DI
  19. Code readability + Naming + Code structure + DSL •

    Unit & Integration folders • Tests names • AAA • @SetUp vs Explicit SetUpTM • DSL
  20. • Unit & Integration folders

  21. None
  22. None
  23. None
  24. Code readability + Naming + Code structure + DSL •

    Tests names
  25. None
  26. Code readability + Naming + Code structure + DSL •

    AAA
  27. None
  28. Code readability + Naming + Code structure + DSL •

    @SetUp vs Explicit SetUpTM
  29. Code readability + Naming + Code structure + DSL

  30. Code readability + Naming + Code structure + DSL •

    DSL
  31. None
  32. One (logical) assert per test + Meaningful asserts + Custom

    matchers • Assert Equals vs Assert That • Actual & Expected • One (logical) assert per test • Hamcrest & Assert J • Custom matchers
  33. • Assert Equals vs Assert That / Actual & Expected

    One (logical) assert per test + Meaningful asserts + Custom matchers
  34. One (logical) assert per test + Meaningful asserts + Custom

    matchers • One (logical) assert per test
  35. None
  36. None
  37. One (logical) assert per test + Meaningful asserts + Custom

    matchers • Hamcrest
  38. • Assert J

  39. One (logical) assert per test + Meaningful asserts + Custom

    matchers • Custom matchers
  40. None
  41. Exceptions • Try/Catch… really? • @Test(expected = ….) • @Rule

    ExpectedException
  42. Exceptions • @Test(expected = ….) • @Rule ExpectedException

  43. Builders + Mothers • Value Objects are leaf in our

    classes tree == No mocks here please • Building value objects “issue” • Builders • Mothers • Builders + Mothers
  44. Builders + Mothers • Builders

  45. Builders + Mothers

  46. Mock providers • DRY using mocks globally • DSL •

    Builders + Mocks = Mocks providers
  47. None
  48. Testing using real things • Mocks, mocks everywhere • Sociable

    Unit Tests • Local resources • Helper & Utility classes
  49. None
  50. None
  51. None
  52. Testing using real things • Helper & Utility classes

  53. Customize your runners + DI • JUnit @RunWith + your

    platform • SetUp and TearDown for expensive resources • DI container and “integration mocks”
  54. Customize your runners + DI • JUnit @RunWith + your

    platform
  55. None
  56. Customize your runners + DI • SetUp and TearDown for

    expensive resources
  57. Customize your runners + DI • SetUp and TearDown for

    expensive resources
  58. Customize your runners + DI

  59. .Thanks!

  60. None
  61. • Mix JVM Languages (Groovy&Scala rule!) • Java 8 fuck

    yeah! • JUnit Lambda • Property-based testing • Mutation Testing Keep an eye on…
  62. Reading a lot • Effective Unit Testing • WEWUT •

    Pragmatic Unit Testing with JUnit • GOOS • The Art of Unit Testing • JUnit in Action • xUnit Patterns • Refactoring