How Scala made my tests more meaningful

How Scala made my tests more meaningful

I have always been interested in improving the way I write and test my systems. Some techniques have been hard to use in languages such as Java. Fortunately Scala with it's power of expression made it much easier. I want to share a few techniques I use on the daily basis.

72d27400135fb93c3e8535791b44f5e3?s=128

Piotr Gabryanczyk

May 24, 2013
Tweet

Transcript

  1. How Scala made my tests more meaningful by Piotr Gabryanczyk

  2. What is a good test? • easy to write •

    easy to read and understand • easy to evolve with the system • bang for buck • meaningful
  3. Which tests are meaningful? • written using abstractions appropriate for

    the component you are testing • using vocabulary defined by the API of the component
  4. Meaningful test

  5. Are integration tests more meaningful?

  6. None
  7. Why is it hard to write integration tests?

  8. Why is it hard to write integration tests?

  9. Why is it hard to write integration tests?

  10. Why is it hard to write integration tests?

  11. Hexagonal Architecture

  12. Adapters raise the level of abstraction

  13. Adapters raise the level of abstraction

  14. Fake for every adapter

  15. Mixing fake and real adapters

  16. Writing fakes is easy - higher order functions

  17. Very bad test data

  18. Very bad test data

  19. Builder Pattern

  20. Builder Pattern

  21. Builder Pattern

  22. It is easy if you build it up gradually

  23. It is easy if you build it up gradually

  24. Everything depends on everything

  25. Peers vs Internals Wikipedia DB Graph Analyzer XML Parser

  26. Fewer dependencies Wikipedia DB Graph Analyzer XML Parser DB Adapter

    Wikipedia Adapter
  27. Creating sub- systems is easy!

  28. Creating sub- systems is easy!

  29. System is a one class with 5 dependencies

  30. Creating of the system is easy!

  31. Writing integration tests in Scala is Easy!

  32. ScalaTest - FreeSpec

  33. DSL example

  34. Infix notation

  35. Implicits

  36. Test Labels

  37. Test Labels

  38. Test Labels

  39. Matchers

  40. Specs2

  41. Expecty

  42. ScalaCheck

  43. Piotr Gabryanczyk @piotrga piotrga@scala-experts.com