Reality Testing
In the world of software development, a decades-long endless debate over the true nature of various testing patterns holds steady: What’s the difference between a Unit Test and an Integration Test? What’s a System Test? Can these overlap? Should they overlap? The answer to these lie in the nature of your code, how it will be utilized, the ecosystem it lives in, and the current phase of the moon.
A Brief History of Unit Testing
It’s 1966, five years following John F. Kennedy’s declaration of an unwavering conviction to send men to the moon by 1970. Roscosmos just beat NASA to the moon by four months, and Alexei Leonov is preparing to take the first small step for man. Allthewhile, Apollo engineers are struggling to simply get off the ground. Roscosmos is running laps around NASA, and Administrator James Webb is running out of rope.
The MIT Instrumentation Lab team assigned to craft the Apollo Guidance Computer was far behind schedule, failing to meet requirements — so much that NASA sent over one of it’s own to oversee the operation. Enter Bill Tindall — in the words of Gene Kranz, Tindall “was pretty much the architect for all of the techniques that we used to go down to the surface of the Moon.”
Tindall began frequenting Massachusetts Avenue, routinely diving into the MIT software development process, returning frank, simplified translations of the work being done in the form of well-circulated memos for NASA staff. Over time, the folks back home in the Lone Star would affectionately reference these as Tindalgrams, internally analogous to the morning newspaper.
One particularly interesting Tindalgram, 66-FM1–75, detailed the bucket of worms known as the Apollo spacecraft computer programs:


Yes, unsatisfactory indeed. We see the term unit test here, for perhaps the first time in archived history. Clearly the practice of unit testing was not new, not typically this type of testing was at the hardware level, so to see it applied to software modules as far back as the late 1960s — that’s pretty neat. If we reach back farther, we can see a reference to these test types used in Gemini, dating back to 1964:
The simulations followed individual unit tests and integrated tests of portions of the software. […] NASA exerted some pressure on MIT to be more consistent in testing, and it eventually adopted a four-level test structure based largely on the verification of the Gemini Mission Control Center developed by IBM in 1964. [1]
Cool, so we’ve unlocked the unit test right? Nope. Unsurprisingly, nobody outside of NASA seems to care - and Unit Testing remains widely unemployed in the realm of software engineering for another 40 years.
It’s 1998, The United States is flirting with impeachment, the MP3 player costs too damn much, and Kent Beck is over software regression. In an assumed but completely unverified drunken programming binge, JUnit 1.0 is born — silently hitting the software development scene. It lays dormant for a few years while Java brews, waiting for the world to discover it’s irreversible impact.

God save the queen you know it’s 1998 when the primary docs come with a cookbook. Here’s an example from the JUnit 1.0 Cookbook, still humming along on Bucknell’s finest Pentium II:
public void testSimpleAdd() {
Money m12CHF= new Money(12, "CHF");
Money m14CHF= new Money(14, "CHF");
Money expected= new Money(26, "CHF");
Money result= m12CHF.add(m14CHF);
assert(expected.equals(result));
}
Fast forward 25 years, the time it took the Human Genome Project to pan out, and we’ve advanced the unit test to roughly this:
@Test
void timeoutNotExceededWithResult() {
String actualResult = assertTimeoutPreemptively(ofSeconds(1), () -> {
return restService.request(request);
});
assertEquals(200, request.getStatus());
}
Rad.
The formal definition of a Unit Test is fairly straightforward:
In computer programming, unit testing is a software testing method by which individual units of source code — sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures — are tested to determine whether they are fit for use. [2]
TL;DR — Testing the smallest logical grouping of code. Typically, this means the method or function level. In python a typical unit test might look like this:
import pytest
def calculate_interest(principal, rate, time):
interest = principal * rate * time / 100
return interestp
def test_calculate_interest():
principal = 1000
rate = 5
time = 1
expected_interest = 50
actual_interest = calculate_interest(principal, rate, time)
assert expected_interest == actual_interest
This is universal, it is absolute. This can be translated to (almost) any modern language, with a nearly identical implementation:
C++
#include <iostream>
#include <cassert>
double calculate_interest(double principal, double rate, double time) {
double interest = principal * rate * time / 100;
return interest;
}
void test_calculate_interest() {
double principal = 1000;
double rate = 5;
double time = 1;
double expected_interest = 50;
double actual_interest = calculate_interest(principal, rate, time);
assert(expected_interest == actual_interest);
}
int main() {
test_calculate_interest();
return 0;
}
Javascript
function calculateInterest(principal, rate, time) {
const interest = (principal * rate * time) / 100;
return interest;
}
function testCalculateInterest() {
const principal = 1000;
const rate = 5;
const time = 1;
const expectedInterest = 50;
const actualInterest = calculateInterest(principal, rate, time);
if (expectedInterest === actualInterest) {
console.log('Test passed.');
} else {
console.log('Test failed.');
}
}
testCalculateInterest();
Python (Spanish)
import pytest
def calcular_interes(principal, tasa, tiempo):
interes = principal * tasa * tiempo / 100
return interes
def test_calcular_interes():
principal = 1000
tasa = 5
tiempo = 1
interes_esperado = 50
interes_actual = calcular_interes(principal, tasa, tiempo)
assert interes_esperado == interes_actual
The unit test holds fast, it has not changed much over it’s life. The nature of the unit test is to uphold the integrity of a small* block of code, so that generations to come can have confidence that the small library holding up modern infrastructure doesn’t suddenly change it’s output.
All Together Now: Integration Testing
Martin Fowler, another living artifact of our predecessors who has a lot to say on testing, declares that integration tests validate the flow between modules:
It was not unusual for one programmer to be responsible for a single module, but this would be big enough that it could take months to build it. … The point of integration testing, as the name suggests, is to test whether many separately developed modules work together as expected. [4]
Modules (in Fowler’s world) could be large portions of software taking a single developer months to write. These are not necessarily the validation of method-chaining; These integration tests ensure that massive portions of code play nice together — a fine-and-dandy notion barring the fact that a “module” is so loosely defined that I could argue an entire http microservice is a “module”.
Ronald J. Leach, author of the undiscovered gem Why 2k? claims the same:
The process of ensuring that programs that are created from individual program modules that work together as a unit is called software integration [3]
Back to our living ancestor: Fowler refers to integration testing as the flow of logic between modules — back in his day this was mostly local, but today this is a combination of local and remote. For remote code (APIs, RPCs, etc) we do not always have the ability to execute our remote service within the test suite. Shoot, most of the time we don’t even have access to the source code within — meaning we must either connect to it and validate the response, or make-up the response based on a known previous response schema. More often than not, we simply make-believe the response in what’s known as a Mocked Response.
Before we get to the best test, let’s take a quick detour and brush up on Mocking.
Mocking
There’s a common thread across Unit and Integration testing: We test against what we expect. Not what’s real, but what we think should be real. We create Mocks, TestDoubles, Fakes, Stubs, Dummy objects; We use files aptly named test.json , test-database.rdb , and user-data.csv. These give us a fixed point in space to work from, solid ground to stand on as we test our system against expected inputs.
This style of testing is known as Blind Testing, in which we make assumptions about a response. In a database-driven application, we may seed a temporary database with fake data. For API calls, we might fetch a convincingly fake response from a local file. Why? Because we want the test suite to run quickly, or because we don’t want to touch a live service, or most often because lower lanes are years out of sync with production and our test suite can’t talk to prod.
Blind Testing works well for applications expecting static, fixed inputs:
- Managed SDK clients
- GUI Interfaces
- NASA Apollo Control Software
But this thinking falls short with more abstract, non-contractual interfaces, such as the “Modern API”. No, not SOAP, but rather almost anything that defaults to json as it’s return format and written post 2008. These are difficult to test against — without a strong contract in place, the inputs and outputs could change at any given time, without your consent or knowledge. Types are optional, and hell usually the whole request signature is optional. These services change all the time with little to no notice. The best one could hope for here is that a Modern API’s author disappears in the wilderness with no replacement to be found, forever locking in that API’s schema.

Of course that will never happen, as new features are introduced and vulnerabilities patched, and API is destined to change over time. Best practices denote the use of a /v<N>/ prefix, or similar method of locking in a set of backwards compatible endpoints you can trust will remain functional with your input for all time — but in reality one has to trust the API author to respect that, and even more difficult: hope they test well enough to catch regression.
So if we can’t trust that an API will remain static enough to emulate with mocked input, what should we do? Do we write mocked tests, updating them as we discover the regressions they did not reveal? Do we hit the live service? Yes to all of the above! For the latter, we’ll turn to a System Test.
System Testing
As though this space wasn’t vague enough, yet another ambiguous term exists to define your test suite: System Testing. Here’s another semi-relevant Fowler quote, to fill space and appeal to academic types:
A software system is made up of a collection of simple, lower-level software modules and […] simpler modules should be put together to form a system [4]
System Testing is a black box test: Pump inputs into your product, validate that outputs match what we expect. We don’t know or care what methods, classes, or even what language the damn thing was written in. We just care that this pile of trash we’re shoving into production passes the turing test for being a reasonably functional pile of trash.
System Testing generally can cover all bases, at the expense of invoking the entire chain of logic many, many times. As product complexity increases, the number of follow-up responses to initial program or API input becomes an infinite set of combinations. Generally, we’d test the hell out of our individual methods, moderately test how they chain together, and very casually test the entire system end to end.
System testing is great, it’s the best — an absolute Chaddington test. Very few lines of code test entire codebases. The only downside to a system test is that one must invoke the entire system — they can’t mock it, that would defeat the purpose.
So What?
I don’t know why I wrote all of that, I just wanted to make this point: If you mock API call responses in your tests, make sure at some point your test suite validates your mock data is in-line with the true response data. Just hit the API — at least once. You’ll thank me later.
References:
[1] Tomayko, J. E. (1988, March 1). Computers in Spaceflight: The NASA experience. NASA Technical Reports Server (NTRS).
[2] Kolawa, Adam. Automated Defect Prevention: Best Practices in Software Management. Wiley, 2007
[3] Leach, Ronald. Introduction to Software Engineering. CRC Press, 2000
[4] Fowler, Martin. (16 January 2018). IntegrationTest.