Cartoon style BOOM in red on a background of an explosion in yellow

Side effects should be isolated, kept in code that is separate from domain logic, and have no conditionals in them. They are the adapters in the “ports and adapters”-pattern.

To test code interacting with the ports, we need test doubles to use as the adapters.

As an example we have pseudo code for a system that sometimes start a siren. The code actually starting the siren is wrapped in a simple class implementing the port-protocol Siren.

protocol Siren {
    void turnOn()

The code starting the siren gets it as a parameter, together with the boolean emergency.

I really don’t want the siren to go off when there is not an emergency.

So to make sure that the function does not even try to start the siren, we use a Dynamite Double. It is a test double that fails the test if the code tries to call its functions. Touch it and it explodes.

class DynamiteDoubleSiren implements Siren {

    void turnOn(){

Instead of using a test double that records if, and how, it has been called, I feel safer if the “no action”-alternative is tested with a dynamite double.


Comment on the blog!

Create a comment by emailing me.
I will then add the comment to the post.

Open an email to start writing.

Related texts

A white and orange wooden roadblock with a warning light attached.

Publish first, review later

A red neonsign of a questionmark

The question trick