知识卡片

普通读书笔记卡 · 6075.d.1.c · 生成模型:未记录

二进制逻辑放入库

理解等级:中级

Rust 的二进制 crate 是运行入口,集成测试无法用 use 导入 main.rs 函数。将主要逻辑放在 lib.rs 并公开所需接口,让 main.rs 负责启动,测试与实际二进制便可调用同一实现。

相关卡片 [[集成测试按使用者验证]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第11章 编写自动化测试(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c11.xhtml`,块 0238) - 结论依据:原文以 `main.rs` 调用 `lib.rs` 说明如何为集成测试提供可导入的核心功能。 - 原始内容:This is one of the reasons Rust projects that provide a binary have a straightforward src/main.rs file that calls logic that lives in the src/lib.rs file. Using that structure, integration tests can test the library crate with use to make the important functionality available.