cpp-mcp/test/README.md

69 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# MCP 单元测试
本目录包含 Model Context Protocol (MCP) 实现的单元测试,基于规范 2024-11-05。
## 测试内容
测试文件包括:
- `test_mcp_message.cpp`: 测试消息相关功能
- `test_mcp_tool.cpp`: 测试工具相关功能
- `test_mcp_resource.cpp`: 测试资源相关功能
- `test_mcp_client.cpp`: 测试客户端相关功能
- `test_mcp_server.cpp`: 测试服务器相关功能
## 构建和运行测试
### 构建测试
```bash
# 在项目根目录创建构建目录
mkdir -p build && cd build
# 配置项目
cmake ..
# 构建项目和测试
make
```
### 运行测试
```bash
# 运行所有测试
make run_tests
# 或者直接运行测试可执行文件
./test/mcp_tests
```
### 运行特定测试
要运行特定的测试,可以使用 Google Test 的过滤功能:
```bash
# 运行所有消息相关测试
./test/mcp_tests --gtest_filter=McpMessageTest.*
# 运行所有工具相关测试
./test/mcp_tests --gtest_filter=McpToolTest.*
# 运行所有资源相关测试
./test/mcp_tests --gtest_filter=McpResourceTest.*
# 运行所有客户端相关测试
./test/mcp_tests --gtest_filter=ClientTest.*
# 运行所有服务器相关测试
./test/mcp_tests --gtest_filter=ServerTest.*
```
## 测试依赖
测试使用 Google Test 框架,该框架会在构建时自动下载和配置。
## 注意事项
- 部分测试需要网络功能,确保本地端口(如 8090、8095未被占用
- 客户端和服务器测试会启动实际的服务器和客户端进行交互测试
- 资源测试会在临时目录创建文件,测试完成后会自动清理