跳转到主要内容

概览

Mirobody 的测试是Catch2 v3 编写的 C++ 单元测试,位于 tests/ 下,编译进单个 mirobody_tests 二进制。它们默认构建,并由 CTest 发现。
测试是一套 C++ Catch2 套件 —— 位于 tests/*_test.cpp 文件。

运行测试

测试作为常规构建的一部分被构建(MIROBODY_BUILD_TESTS CMake 选项默认为 ON,Android / iOS 除外):
./build.sh                      # builds the engine + tests
ctest --test-dir build          # run the whole suite via CTest
或直接运行测试二进制并使用 Catch2 的过滤:
./build/tests/mirobody_tests                 # all tests
./build/tests/mirobody_tests "[fhir]"        # only the [fhir]-tagged tests
./build/tests/mirobody_tests "[transcode]"   # only transcoder tests
在 Windows 上,二进制为 build\tests\mirobody_tests.exe。构建目录名随你的后端选择器而定(如 build_sqlite/tests/mirobody_tests)。

测试布局

测试镜像 src/ 的模块树。当前覆盖包括:
领域测试
FHIRtests/fhir/units_test.cpp(UCUM 归一化)、tests/fhir/resource_test.cpp(资源校验)
Transcodetests/transcode/document_test.cpptests/transcode/image_test.cpptests/transcode/file_test.cpp
LLM 客户端tests/llm/* —— SSE 解析器、OpenAI / Gemini / MiroThinker 聊天、realtime / live
MCPtests/mcp/tool_test.cpptests/mcp/resource_test.cpp(工具 / 资源注册)
Chattests/chat/agent_test.cppevent_test.cpphistory_test.cpppersist_test.cpp
基础设施tests/cache/tests/jwt/tests/oauth/pkce_test.cpptests/storage/tests/memory/tests/circle/tests/utils/
测试目标直接链接那些自注册对象(mcp_toolsmcp_resourcesagent_impls),方式与 app 目标相同 —— 这正是注册测试能观察到编译进程序的工具与 agent 的原因。

编写一个测试

在匹配的 tests/<module>/ 目录下新增一个 *_test.cpp,然后在 tests/CMakeLists.txtadd_executable(mirobody_tests ...) 源文件列表中登记它。
#include <catch2/catch_test_macros.hpp>
#include "fhir/units/normalize.hpp"

using namespace mirobody::fhir::units;

TEST_CASE("UCUM normalization folds common spellings", "[fhir][units]") {
    REQUIRE(normalize_unit("MG/DL") == "mg/dL");
    REQUIRE(normalize_unit("mmHg")  == "mm[Hg]");

    ParsedQuantity q = parse_value_unit("<5.6 mg/dL");
    REQUIRE(q.comparator == "<");
    REQUIRE(q.value == Catch::Approx(5.6));
    REQUIRE(q.unit == "mg/dL");
}
[module] 给测试打标签,以便可被选中(mirobody_tests "[units]")。

单元套件覆盖什么 —— 又不覆盖什么

  • 纯逻辑 / 无需数据库的逻辑(单位引擎、FHIR 资源校验器、SSE 解析、PKCE、JWT、HMAC 签名)由无外部依赖的快速单元测试覆盖。
  • 依赖数据库的路径(FHIR REST 处理器、聊天持久化)针对一个运行中的、带数据库的服务器端到端地演练,而非在单元二进制中。
  • Vendor 客户端在套件中没有单元测试 —— 它们调用真实的第三方 API,因此针对一个运行中的服务器手动验证(参见 Provider 测试)。它们的元数据(VendorInfo)无需凭据、本可断言,但传输层靠手工验证。

持续集成

CI 在推送时运行构建与测试。流水线定义在仓库的 CI 配置(.gitlab-ci.yml)中。(verify the exact jobs in the repo.)

下一步

贡献指南

构建与修改工作流

Provider 测试

手动验证一个 vendor 客户端

Provider 集成

新增一个 vendor::Vendor

文件处理

转码器及其测试