While writing software, we are faced with lots and lots of interfaces.
The public interface for some tool or module or package or whatever is usually referred to as the API, the CLI, or simply the user interface.
In this post, when considering an interface, I am specifically referring to APIs and CLIs.
Sometimes, we find a software component that does exactly what we want, but the interface is not what we want.
That’s where software interface adapters come to the rescue.
Adapters are helpful in many stages of the design and development of just about anything.
Software interface adapters are perfect for functional testing.
On this site, I use a flavor of TDD that focuses on functional testing.
I’ve usually got a couple of goals:
- I want to test the public interface: either API, CLI, or both.
- I want the tests tat make up my regression test suite to be as easy to write as possible, so that it’s simple to add new tests as needed.
Often, these goals are at odds. The API/CLI may just not be convenient for easy testing.
That’s an ideal place to develop an interface adapter.
In this post, I’ll describe how interface adapters can be easily specified and implemented in python.
As a working example, I’ll describe the interface adapter that I need for testing markdown.py.