Here’s an example of testing a simple command line application. The application reads a string from the command line, encodes it using ROT-13, and outputs the result.
The production code uses the optional A-Frame Architecture pattern. App is the application entry point. It depends on Rot13, a Logic class, and CommandLine, an Infrastructure class. Additional patterns are mentioned in the source code.
The tests of App look like end-to-end integration tests, but they’re actually unit tests. Technically, they’re Narrow, Sociable tests, which means they’re unit tests that execute code in dependencies.
As narrow tests, the tests only care about testing App.run(). Each of the dependencies is expected to have tests of their own, which they do.
The tests use a NullableCommandLine to throw away stdout and Configurable Responses to provide pre-configured command-line arguments. They also use Output Tracking to see what would have been written to stdout.
If you’re familiar with mocks, you might assume CommandLine is a test double. But it’s actually production code with an “off” switch and the ability to monitor its output.
The patterns shine in more complex code that has multiple layers of dependencies. Find more examples here:
Complex example. The blinged-out version of the above example. A web application and microservice that performs ROT-13 encoding. Production-grade code with error handling, logging, timeouts, and request cancellation. (JavaScript or TypeScript with Node.js)
TDD Lunch & Learn Screencast. A series of one-hour webinars that demonstrate how to use the patterns. (JavaScript with Node.js)
Nullables Livestream. A series of three-hour livestreams with James Shore and Ted M. Young. They pair on applying the patterns to an existing web application. (Java with Spring Boot)