简体   繁体   English

如何在 rust 的 src 之外的测试目录中使用 lib?

[英]How to use lib in test directory which is outside of src in rust?

I have a following folder structure,我有以下文件夹结构,

.
├── utils/
│   ├── helpers.rs
│   └── lib.rs
├── tests/
│   └── helpers.rs
└── Cargo.toml

lib.rs just includes helpers.rs , lib.rs只包括helpers.rs

mod helpers;

So how do use utils::helpers inside tests/helpers.rs ?那么如何在tests/helpers.rs中使用utils::helpers呢?

The tests folder contains your integration tests. tests文件夹包含您的集成测试。 Those tests may only use the public interface of your library, and not test internals that are hidden to a user of your library.这些测试可能只使用您库的公共接口,而不是测试对您的库用户隐藏的内部。

If you want your users to use utils::helpers , then make sure that it is pub lic and write integration tests from the downstream developers perspective.如果您希望您的用户使用utils::helpers pub请确保它是公开的,并从下游开发人员的角度编写集成测试。 However, if you only want to write unit tests (which is much more likely), then add them in the helpers module itself.但是,如果您只想编写单元测试(这更有可能),则将它们添加到helpers模块本身中。

See "Test Organization" in The Rust Programming Language for more information.有关详细信息,请参阅Rust 编程语言中的“测试组织”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM