#[cfg(test)]
mod tests {
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;
#[test]
fn test_add() {
assert_eq!(add(1, 2), 3);
}
#[test]
fn test_bad_add() {
// This assert would fire and test will fail.
// Please note, that private functions can be tested too!
assert_eq!(bad_add(1, 2), 2);
}
}
fn add(a: i8, b: i8) -> i8 {
return a + b;
}
fn bad_add(a: i8, b: i8) -> i8 {
return a * b;
}
Rust 从外部(用于测试模块)范围导入名称
转载
use super :: *;
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
下一篇:抽象类
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
从excel导入数据,画六边形分箱图
画六边形分箱图
FT数据成图 -
【Rust 基础篇】Rust 模块详解
在 Rust 中,可以使用mod关键字来定义一个模块。模块可以包含其他模块、函数、结构体、枚举和常量
rust 开发语言 后端 Rust 访问控制