LangGraph · Lesson 104 of 120
Testing Graphs
Paths and outputs.
Node tests check the pieces. Graph tests check the wiring. Did the right nodes run, in the right order? Does each branch end with the right result? Streaming updates makes the path easy to check.

- Node tests: pieces
- Graph tests: wiring
- Check the path
Checking the path
The path helper streams the graph with updates mode, and collects the names of the nodes that ran. We assert the order pipeline runs clean, price, then receipt, and that the final receipt is right. Run it. Both checks pass.
test_graph.pypython
from order_graph import graph
def path(inputs, thread):
config = {"configurable": {"thread_id": thread}}
return [node for step in graph.stream(inputs, config, stream_mode="updates") for node in step]
assert path({"title": "dune", "quantity": 1}, "p1") == ["clean", "price", "receipt"]
print("path ok:", path({"title": "circe", "quantity": 1}, "p2"))
final = graph.invoke({"title": "circe", "quantity": 3}, {"configurable": {"thread_id": "p3"}})
assert final["receipt"] == "3 x Circe = £32.97"
print("receipt ok:", final["receipt"])Output
path ok: ['clean', 'price', 'receipt'] receipt ok: 3 x Circe = £32.97
Also uses order_graph.py
from typing import TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph, START, END
PRICES = {"Dune": 9.99, "Circe": 10.99}
class Order(TypedDict):
title: str
quantity: int
total: float
receipt: str
def clean(s):
return {"title": s["title"].strip().title()}
def price(s):
return {"total": round(PRICES[s["title"]] * s["quantity"], 2)}
def receipt(s):
return {"receipt": f"{s['quantity']} x {s['title']} = £{s['total']}"}
b = StateGraph(Order)
b.add_sequence([clean, price, receipt])
b.add_edge(START, "clean"); b.add_edge("receipt", END)
graph = b.compile(checkpointer=InMemorySaver())What to check
For every branch, write one test that takes it. Check the path, and the final state. For loops, check they stop. And for interrupts, check that the run pauses, and resumes correctly.
| key | value |
|---|---|
| Each branch | one test |
| Path | nodes in order |
| Loops | they stop |
| Interrupts | pause and resume |
Summary
Graph tests check the path through the graph, and the final state, for every branch. Next, debugging when something goes wrong.
Key takeaways- Collect the path
- Assert the order
- Assert the result
Next up: Debugging — tracing and history