liveBook · Manning

End-to-end testing

As explained in Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform

End-to-end testing verifies the behavior of an entire system across its integrated components and external interfaces.

End-to-end testing dynamically analyzes infrastructure resources and complete user workflows to verify that infrastructure changes preserve end-user functionality. Unlike integration tests, it checks whether the application can actually serve a request, not merely whether resources and permissions were configured successfully. section 6.5 section 6.8

Use end-to-end tests as the final environment-level check:

  • Deploy the changed configuration to a testing environment after unit tests and integration tests pass. section 6.7.2
  • Retrieve the application endpoint from the infrastructure configuration and issue an HTTP request. section 6.5
  • Repeat the check in production after release, while adapting resource creation or deletion to the environment. section 6.5 section 6.7.2
  • Retain tests that provide reliable information, remove flaky tests, and convert team knowledge about recurring failures into coverage. section 6.7.3

Testing a Cloud Run application

A Python pytest fixture generates the service configuration, initializes and applies the infrastructure, retrieves the resulting public URL, requests the running page, and destroys the temporary service afterward. A failed request can expose a configuration change that prevents authenticated users from reaching the application. section 6.5

Listing 6.5 End-to-end test for GCP Cloud Run service
from main import generate_json, SERVICE_CONFIGURATION_FILE
import os
import pytest
import requests                       
import test_utils                                                     #1
 
TEST_SERVICE_NAME = 'hello-world-test'
 
 
@pytest.fixture(scope='session')                                      #2
def apply_changes():                                                  #2
   generate_json(TEST_SERVICE_NAME)                                   #3
   assert os.path.exists(SERVICE_CONFIGURATION_FILE)                  #3
   assert test_utils.initialize() == 0                                #2
   yield test_utils.apply()                                           #2
   assert test_utils.destroy() == 0                                   #4
   os.remove(SERVICE_CONFIGURATION_FILE)                              #4
 
 
@pytest.fixture                                                       #5
def url():                                                            #5
   output, error = test_utils.output('url')                           #5
   assert error == b''                                                #5
   service_url = output.decode(encoding='utf-8').split('\n')[0]       #5
   return service_url                                                 #5
 
 
def test_url_for_service_returns_running_page(apply_changes, url):    #6
   response = requests.get(url)                                       #6
   assert "It's running!" in response.text                            #7

Inspect the pytest implementation that creates the test service, checks its endpoint, and cleans up the testing environment. section 6.5

How Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform covers it

How deep it goes
Explains endpoint-driven execution, environment sequencing, cleanup, and reliability trade-offs without descending into application internals.
Examples
Uses a GCP Cloud Run service, a public application URL, an HTTP GET request, and a Python pytest fixture with cleanup.
What it assumes
Assumes unit and integration testing, infrastructure deployment, environment management, and access to an application endpoint.
What you can do after
Apply via pytest and HTTP requests to validate deployed infrastructure workflows in testing and production environments.
How it connects
Connects end-to-end testing with unit testing, integration testing, continuous delivery, configuration drift, and monitoring.

Also explained in

Compare how 12 books explain end-to-end testing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform. The section links point to the parts of the book it draws on.