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











