gpt4 book ai didi

testing - 对 crate 中的模块运行测试

转载 作者:行者123 更新时间:2023-11-29 08:06:58 24 4
gpt4 key购买 nike

我正在编写一个包,其中包含分布在多个文件中的多个模块。这些模块是相互依赖的,即一些模块使用这个 crate 中的其他模块。

是否可以在这些模块中独立于 crate 中的其他模块运行测试?如果 some_module.rs 包含对该 crate 中其他模块的引用,则运行 rust test some_module.rs 不起作用。运行 rust test my_crate.rc 确实有效,但它从所有 crate 模块运行测试,这不是我想要的。

最佳答案

可以运行测试的一个子集:

> rustc --test my_crate.rc
> ./my_crate some_module

... test output ...

这将运行完整路径包含 some_module 的任何函数。有一个 fairly detailed help page for unit testing在维基上,包括 this use case .

请注意 rust test 不支持此功能(目前!),因此您必须编译测试运行程序并手动调用它(或者,编写一个 Makefile/脚本来执行此操作)。

关于testing - 对 crate 中的模块运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18051645/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com