Hexagonal Architecture: Testing and Adaptation Strategies

Hexagonal architecture applied

Alistair Cockburn invented hexagonal architecture to address the spread of business logic into other unrelated parts of the software. He laid out three factors of this problem:

  • Testing is more difficult when the tests become dependent on the user interface.

  • Coupling makes it impossible to shift between human-driven use and a machine-driven one.

  • Switching to new infrastructure is difficult or impossible when the need or opportunity presents itself.

The solution was to isolate the application and its core from external concerns by placing APIs, the ports, on the boundary of the application that used adapters to integrate with external components. This pairing of abstraction and concrete implementations would allow external components such as new UIs, test harnesses with mocks, and new infrastructure to be swapped in and out much more easily.

Get hands-on with 1400+ tech skills courses.