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

Love your tests

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.

Tuenti

November 27, 2015
Tweet

More Decks by Tuenti

Other Decks in Technology

Transcript

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

    • Refactoring, refactoring, refactoring • It is professional, guys :)
  2. “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.”
  3. • Code coverage != Test quality • Don’t Repeat Yourself

    (Globally) • Mocks, mocks everywhere • Test smells
  4. 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
  5. Code readability + Naming + Code structure + DSL •

    Unit & Integration folders • Tests names • AAA • @SetUp vs Explicit SetUpTM • DSL
  6. 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
  7. • Assert Equals vs Assert That / Actual & Expected

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

    matchers • One (logical) assert per test
  9. Builders + Mothers • Value Objects are leaf in our

    classes tree == No mocks here please • Building value objects “issue” • Builders • Mothers • Builders + Mothers
  10. Mock providers • DRY using mocks globally • DSL •

    Builders + Mocks = Mocks providers
  11. Testing using real things • Mocks, mocks everywhere • Sociable

    Unit Tests • Local resources • Helper & Utility classes
  12. Customize your runners + DI • JUnit @RunWith + your

    platform • SetUp and TearDown for expensive resources • DI container and “integration mocks”
  13. • Mix JVM Languages (Groovy&Scala rule!) • Java 8 fuck

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

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