gpt4 book ai didi

testing - 我如何在 Rust 中测试私有(private)方法?

转载 作者:行者123 更新时间:2023-11-29 08:33:21 49 4
gpt4 key购买 nike

我如何在 Rust 中测试私有(private)方法?我没有找到任何关于它的信息。文档中也没有任何信息。

最佳答案

使用 #[test] 时,私有(private)或公共(public)方法没有什么特别之处——您只是在编写可以访问它们可以访问的任何内容的完美正常函数。

fn private_function() {
}

#[test]
fn test_private_function() {
private_function()
}

外部测试,例如 tests/*.rsexamples/*.rs 如果您使用的是 Cargo 或 doc 测试,则无法访问私有(private)成员;他们也不应该:此类测试旨在成为公共(public) API 测试,而不是处理实现细节。

关于testing - 我如何在 Rust 中测试私有(private)方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41775900/

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