Harness¶
Test harness for workflow testing.
Classes¶
- class arshai.testing.harness.MockMemoryManager[source]¶
Bases:
objectMock memory manager for testing agents with caching.
Example
agent = MyAgent() agent.memory = MockMemoryManager()
# Test caching behavior result = await agent.cached_method(data)
- class arshai.testing.harness.WorkflowTestHarness[source]¶
Bases:
objectTest harness for workflow testing.
Provides utilities for testing workflows with mocked nodes, execution tracking, and result verification.
Example
harness = WorkflowTestHarness()
# Test with mocked nodes result = await harness.test_workflow(
workflow=my_workflow, input_state=test_state, mock_nodes={
“external_api”: {“status”: “success”}, “database”: {“data”: [1, 2, 3]}
}
)
# Verify execution path assert harness.executed_nodes == [“input”, “external_api”, “database”, “output”]
- async test_workflow(workflow, input_state, mock_nodes=None, record_execution=True)[source]¶
Test workflow with optional mocked nodes.
- Parameters:
workflow (
BaseWorkflowOrchestrator) – Workflow to testinput_state (
IWorkflowState) – Input statemock_nodes (
Optional[Dict[str,Any]]) – Dict of node names to mock outputsrecord_execution (
bool) – Record execution details
- Return type:
- Returns:
Workflow result
- assert_node_executed(node_name)[source]¶
Assert that a specific node was executed.
- Parameters:
node_name (
str) – Name of the node to check- Raises:
AssertionError – If node was not executed
- assert_execution_order(expected_order)[source]¶
Assert nodes were executed in specific order.
- Parameters:
- Raises:
AssertionError – If execution order doesn’t match
- assert_node_not_executed(node_name)[source]¶
Assert that a specific node was NOT executed.
- Parameters:
node_name (
str) – Name of the node to check- Raises:
AssertionError – If node was executed