Test-driven development

A site dedicated to the noble art of TDD


Project maintained by zhendrikse Hosted on GitHub Pages — Theme by mattgraham

Communication with the outside world


This page is about the hexagonal architecture.

Ports and adapters

The above picture has been taken from Growing Object-Oriented Software Guided by Tests by Steve Freeman and Nat Pryce (Creative Commons License).

The central idea here is to move the dependencies to external systems to the boundaries of your domain model. By defining ports (realized as interfaces) and adapters (implementations of these interfaces that connect to the external system), we

Since some of the coding katas in this repository specifically address this topic, this page discusses the required concepts that are common to all these katas. These concepts all fall under the umbrella of what’s generally known as the Hexagonal Architecture (a.k.a. Ports and Adapters). Uncle Bob elaborated on this concept and coined it the clean architecture.

TDD and communication with external systems

A question that is often raised is: How do I practice TDD when I have to deal with the dependencies of my system to the outside world? Examples of such dependencies are databases, file systems, networks, etc. So isn’t it inevitable then that I eventually have to include tests involving these external systems in my tests and as a consequence my tests (gradually) become slow?

Many people are inclined to introduce mocks into their tests at this point, but apparently these people haven’t heard of the don’t mock what you don’t own principle. A good but somewhat long read about this topic is also Martin Fowler’s well-known mocks aren’t stubs.

So what do we do then when mocks are not meant to be used for this purpose? The answer is to apply dependency inversion and to use so-called ports and adapters.

Hexagonal architecture

Hexagonal architecture

References


Share on: