Software reliability is the likelihood that software continues performing required functions correctly under stated conditions. Integration tests protect it by exercising real service boundaries, where networks, outages, races, and corrupted data can expose failures that unit tests miss. section 12.0 section 12.6
A reliable integration suite must be trustworthy itself. Fixed shared infrastructure lets tests interfere with one another, producing mysterious failures and weakening confidence in the software. section 12.6
Build reliability into integration testing by:
- Provisioning queues, buckets, and other dependencies on demand for each test. section 12.6
- Injecting those isolated dependencies into the service rather than pointing tests at fixed environments. section 12.6
- Randomizing resource names so prior failures cannot collide with later tests. section 12.6
- Using namespaces to support cleanup at test, suite, owner, or global scope. section 12.6
An isolated integration test
Create input and output queues plus a bucket immediately before the test, construct the service with those dependencies, run the service, assert its behavior, and tear the resources down afterward. A randomized namespace prevents collisions with other tests.
Listing 12.13 Creating isolated dependencies for a test
@Test
void myCoolIntegrationTest () {
// spinning up infrastructure right before we run the test
Queue inputQueue = cloudSDK.createQueue("my-own-input-queue");
Queue outputQueue = cloudSDK.createQueue("my-own-output-queue");
Bucket bucket = cloudSDK.createBucket("bucket-for-my-test");
// We construct our service using the placeholder infrastructure.
// (This, of course, depends on us using good Dependency
// Injection practices)
MyService service = new MyService(inputQueue, outputQueue, bucket);
// now it’s pretty standard arrange, act, assert.
// just that the “arrange” is done against service infrastructure
// that’s completely isolated to our test
inputQueue.put(makeInputMessage());
service.run()
// then we make sure everything behaved the way we expect.
// for instance, the item in the input queue should have been consumed
assertEquals(inputQueue.poll(), Optional.empty());
// we want something in the output queue
assertNotEquals(outputQueue.poll(), Optional.empty());
// and something written to our bucket
assertEquals(/* lookup item in bucket here */);
// then blow everything away
cloudSDK.deleteQueue(inputQueue.name());
cloudSDK.deleteQueue(outputQueue.name());
cloudSDK.deleteBucket(bucket.name());
}Shows the small setup, dependency injection, exercise, and assertion pattern used to isolate real infrastructure for an integration test. section 12.6




















