Distributed and UI test boundaries
Distributed and UI test boundaries
Distributed and UI tests cover boundaries that a single-process unit test cannot: consumer/provider contracts, retries, message delivery, and actual user interactions.
A contract test describes the fields, types and observable semantics one consumer relies on; verify the provider against the same expectations in CI. A permissive parser may accept additional fields, but a renamed required field or changed meaning breaks it. A consumer mock alone cannot prove provider compatibility. An end-to-end test includes the real participating components and may exercise fewer critical journeys because diagnosis is harder. A deterministic failure schedule is excellent for checking a state machine, but it does not prove durability, network retry behavior, broker acknowledgement or concurrent delivery. Use stable tenant-scoped IDs and persist outcomes atomically with updates. Inject clocks rather than waiting; freeze the chosen time and explicitly advance it. Add failure cases for cancellation before commit, lost acknowledgement after commit and replay after restart. A browser smoke test should run with an isolated account and actual rendered page, verify accessible labels, keyboard focus, validation, forbidden actions and final persisted state. A Testcontainers setup is an opt-in real infrastructure test, not a simulator; verify readiness, timeouts, teardown and resource ownership. Below, all examples are deterministic local models and not deployed-system results. For a concrete container fixture design and browser test checklist, see lab-fixtures/testing/approved-boundaries.md. The custom clock below only replaces GetUtcNow; an approved FakeTimeProvider from the Microsoft testing package can be used to drive compatible timers as well.
Baseline: .NET 10 / C# 14. All C# results below are reasoned, not executed. Models, in-process integrations and actual runtime or UI tests are distinguished.
Check an additive JSON contract and a breaking change
Validate the consumer-required fields, not every property. These strings are synthetic provider-response samples.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits.
using System;using System.Text.Json;bool Accepts(string json) { try { using var doc = JsonDocument.Parse(json); var root = doc.RootElement; return root.ValueKind == JsonValueKind.Object && root.TryGetProperty("sku", out var sku) && sku.ValueKind == JsonValueKind.String && !string.IsNullOrEmpty(sku.GetString()) && root.TryGetProperty("available", out var n) && n.ValueKind == JsonValueKind.Number && n.TryGetInt32(out int units) && units >= 0; } catch (JsonException) { return false; }}foreach (string json in new[] { "{\"sku\":\"A\",\"available\":3}", "{\"sku\":\"A\",\"available\":3,\"warehouse\":\"north\"}", "{\"sku\":\"A\",\"stock\":3}", "{\"sku\":\"A\",\"available\":\"3\"}", "{" }) { Console.WriteLine(Accepts(json) ? "accepted" : "breaking");}Expected result (not executed):
acceptedacceptedbreakingbreakingbreakingThe consumer accepts additive fields and rejects missing fields, wrong types and malformed JSON. These are sample responses only; verify the provider against the same expectations in a real contract suite.
Model lost acknowledgement and replay
Run a fixed sequential schedule with an in-memory outcome map. Do not interpret it as a broker test.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits.
using System;using System.Collections.Generic;var seen = new HashSet<string>(); int stock = 5;foreach (string id in new[] { "tenant-A/order-1", "tenant-A/order-1", "tenant-A/order-2" }) { if (seen.Add(id)) { stock--; Console.WriteLine("applied"); } else Console.WriteLine("duplicate");}if (stock != 3) throw new Exception("duplicate effect");Console.WriteLine($"stock={stock}");Expected result (not executed):
appliedduplicateappliedstock=3This sequential model does not check payload conflicts, atomic persistence or multithreaded access. Test those separately with the real storage and transport.
Test an expiry boundary with an injected clock
The application accepts a reservation only before its expiry. Advance a controlled clock to the exact boundary.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits.
using System;var clock = new LabClock(new DateTimeOffset(2026, 1, 1, 0, 0, 0, TimeSpan.Zero));var expiry = clock.GetUtcNow().AddSeconds(10);bool Active() => clock.GetUtcNow() < expiry;Console.WriteLine(Active()); clock.Advance(TimeSpan.FromSeconds(9));Console.WriteLine(Active()); clock.Advance(TimeSpan.FromSeconds(1));Console.WriteLine(Active());sealed class LabClock(DateTimeOffset now) : TimeProvider { private DateTimeOffset current = now; public override DateTimeOffset GetUtcNow() => current; public void Advance(TimeSpan amount) => current += amount;}Expected result (not executed):
TrueTrueFalseThe fake overrides wall-clock UTC only, not timers or timestamps. Expiry is exclusive by the business rule; no sleep or scheduling assumptions are needed.
Apply the concept
Create a test matrix for reserving a stock item from a browser through a message-driven backend. Include a lost acknowledgement and keyboard-only completion.
Use the manual practice and knowledge check. Do not deploy or publish these fixtures.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Distributed and UI test boundaries — knowledge check
Apply the lesson concepts to the following scenarios.
What does an additive JSON property imply?
What must a provider contract test do?
What cannot an in-memory replay model prove?
Why inject a clock?
What verifies keyboard focus and actual labels?