This release is a pre-release and may not be stable for production use.
Microsoft Agents Testing
Testing utilities for the Microsoft 365 Agents SDK for Python. This package provides an in-memory channel adapter, fluent conversation assertions, and a mock user-token client so agent behavior can be tested without a live channel or token service.
Release Notes
| Version | Date | Release Notes |
|---|---|---|
| 1.5.0 | 2026-08-26 | 1.5.0 Release Notes |
Features
TestAdapterruns activities through the normal middleware and agent pipeline while capturing outgoing activities in memory.TestFlowprovides fluent helpers for sending activities and asserting replies in order.MockUserTokenClientsupports stored tokens, magic codes, sign-out, token status, and token-exchange scenarios.- Async-first APIs work with the SDK's standard
TurnContextandChannelAdapterabstractions.
Installation
pip install microsoft-agents-testing
Quick Start
import pytest
from microsoft_agents.hosting.core import TurnContext
from microsoft_agents.testing import TestAdapter, TestFlow
@pytest.mark.asyncio
async def test_echo_agent():
adapter = TestAdapter()
async def on_turn(context: TurnContext):
await context.send_activity(f"Echo: {context.activity.text}")
await (
TestFlow(adapter, on_turn)
.send("hello")
.assert_reply("Echo: hello")
.assert_no_more_replies()
.start_test()
)
Reply Assertions
Replies can be matched by exact text, partial text, activity properties, or a custom synchronous or asynchronous validator:
from microsoft_agents.activity import Activity, ActivityTypes
def validate_reply(reply: Activity):
assert reply.type == ActivityTypes.message
assert reply.text is not None
assert reply.text.startswith("Hello")
await (
TestFlow(adapter, on_turn)
.send("hi")
.assert_reply_contains("Hello")
.send("details")
.assert_reply(validate_reply)
.start_test()
)
TestFlow also supports conversation updates, typing indicators, delays,
mixed activity transcripts, and configurable reply timeouts.
Testing OAuth Flows
TestAdapter uses MockUserTokenClient by default. Add a token to test an
already-authenticated user:
adapter = TestAdapter(channel_id="msteams")
adapter.add_user_token(
connection_name="my-connection",
channel_id="msteams",
user_id="user1",
token="test-token",
)
Token exchange can be configured in the same way:
adapter.add_exchangeable_token(
connection_name="my-connection",
channel_id="msteams",
user_id="user1",
exchangeable_item="exchange-token",
token="exchanged-token",
)
These tokens are stored only in memory and are intended exclusively for tests.
Scope
The adapter models the turn-processing boundary needed by unit tests. It does not contact Connector Service, create real proactive conversations, or emulate channel-specific delivery behavior.
Related Packages
microsoft-agents-hosting-coreprovides the agent runtime and abstractions used by this package.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file microsoft_agents_testing-1.6.1.dev1.tar.gz.
File metadata
- Download URL: microsoft_agents_testing-1.6.1.dev1.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30ca2db3fa2ce5f5f93ebb32789c03a780d19e093a1210fb8e98926d11d1525f
|
|
| MD5 |
267d87015e8fd957afcd8e86f9c1c4f5
|
|
| BLAKE2b-256 |
df79fe51486938ca82b7eb2dc6258cb422434b58ba5e7ee043ba9c902dbd2a5a
|
File details
Details for the file microsoft_agents_testing-1.6.1.dev1-py3-none-any.whl.
File metadata
- Download URL: microsoft_agents_testing-1.6.1.dev1-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ba783dee7e5ac0afecd93642838dcd54d78b28e7da3fb239ca4f3bec389ffae
|
|
| MD5 |
24216570d1bfb1de35b5c9c7a81f1e1a
|
|
| BLAKE2b-256 |
bffd0a8514271b335add7541435ba07281fd2494a67d7ccad6bcec716cbb7bf7
|