cpp-mcp/test/README.md

59 lines
1.4 KiB
Markdown
Raw Normal View History

2025-03-17 16:29:33 +08:00
# MCP Unit Tests
2025-03-08 23:44:34 +08:00
2025-03-17 16:29:33 +08:00
This directory contains unit tests for the Model Context Protocol (MCP) implementation, based on the 2024-11-05 specification.
2025-03-08 23:44:34 +08:00
2025-03-17 16:29:33 +08:00
## Building and Running Tests
2025-03-08 23:44:34 +08:00
2025-03-17 16:29:33 +08:00
### Building Tests
2025-03-08 23:44:34 +08:00
```bash
2025-03-17 16:29:33 +08:00
# Create a build directory in the project root
2025-03-08 23:44:34 +08:00
mkdir -p build && cd build
2025-03-17 16:29:33 +08:00
# Configure the project
2025-03-08 23:44:34 +08:00
cmake ..
2025-03-17 16:29:33 +08:00
# Build the project and tests
2025-03-08 23:44:34 +08:00
make
```
2025-03-17 16:29:33 +08:00
### Running Tests
2025-03-08 23:44:34 +08:00
```bash
2025-03-17 16:29:33 +08:00
# Run all tests
2025-03-08 23:44:34 +08:00
make run_tests
2025-03-17 16:29:33 +08:00
# Or directly run the test executable
2025-03-08 23:44:34 +08:00
./test/mcp_tests
```
2025-03-17 16:29:33 +08:00
### Running Specific Tests
2025-03-08 23:44:34 +08:00
2025-03-17 16:29:33 +08:00
To run specific tests, you can use Google Test's filtering capability:
2025-03-08 23:44:34 +08:00
```bash
2025-03-17 16:29:33 +08:00
# Run all message-related tests
2025-03-08 23:44:34 +08:00
./test/mcp_tests --gtest_filter=McpMessageTest.*
2025-03-17 16:29:33 +08:00
# Run all tool-related tests
2025-03-08 23:44:34 +08:00
./test/mcp_tests --gtest_filter=McpToolTest.*
2025-03-17 16:29:33 +08:00
# Run all resource-related tests
2025-03-08 23:44:34 +08:00
./test/mcp_tests --gtest_filter=McpResourceTest.*
2025-03-17 16:29:33 +08:00
# Run all client-related tests
2025-03-08 23:44:34 +08:00
./test/mcp_tests --gtest_filter=ClientTest.*
2025-03-17 16:29:33 +08:00
# Run all server-related tests
2025-03-08 23:44:34 +08:00
./test/mcp_tests --gtest_filter=ServerTest.*
```
2025-03-17 16:29:33 +08:00
## Test Dependencies
2025-03-08 23:44:34 +08:00
2025-03-17 16:29:33 +08:00
Tests use the Google Test framework, which is automatically downloaded and configured during the build process.
2025-03-08 23:44:34 +08:00
2025-03-17 16:29:33 +08:00
## Notes
2025-03-08 23:44:34 +08:00
2025-03-17 16:29:33 +08:00
- Some tests require network functionality, ensure that local ports (such as 8090, 8095) are not in use
- Client and server tests will start actual servers and clients for interaction testing
- Resource tests will create files in a temporary directory, which will be automatically cleaned up after testing