A Philosophy of Testing 4: Scenario Tests

  • On the one hand, there are unit tests — atomized little tests, typically focusing on a single class or just a few.
  • On the other hand, there are integration tests — “opaque” tests that run the application for real, often in the context of other running services, only looking at it from the outside with an external test driver.

Structure of a Scenario Test

Why?

Emulating External Services

Using the Real Thing

When to Use Unit Tests

  • Data structures that are genuinely complicated — in particular, while you shouldn’t usually be using mutable structures, even a complex immutable structure needs careful testing. (Use ScalaCheck here.)
  • Complex algorithms. In particular, if you have functions that are highly sensitive to their inputs, then it is typically worth writing some focused tests for those.
  • Hard-to-hit code. This tends to be obscure error pathways that are difficult to exercise except under extreme circumstances. Unit tests for those are sometimes worthwhile, although I would always ask whether there is a feasible way to hit them with a scenario test instead.

Conclusion

  • Services tend to be mostly plumbing.
  • Bugs arise less often in plumbing classes, and more between them.
  • You should focus on testing the interactions between the components.
  • The best way to do that is by testing the entire application on realistic inputs.
  • Emulate the external services used by the components, with little simulators that are fast and under precise control.

Lifelong programmer and software architect, specializing in online social tools and (nowadays) Scala. Architect of Querki (“leading the small data revolution”).

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How I Learned Kubernetes

Unity: Real example shows the difference of three Canvas UI Scale Modes

Learn How To Keep Under Control The Disk Usage of Your Local Docker Environment

It’s Time To Retire Your Old Software

Creating an AKS Cluster With Application Gateway (AGIC)

RFID based Attendance System using Atmega32 microcontroller

SageMath: Doing Math in Python

Insomnia Client & XeroAPI Auth

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mark "Justin" Waks

Mark "Justin" Waks

Lifelong programmer and software architect, specializing in online social tools and (nowadays) Scala. Architect of Querki (“leading the small data revolution”).

More from Medium

A Philosophy of Testing 8: Summary

[Scala] Implicit Parameters

Scala: Partial application

Side effects and IO