Hello
In the Rust documentation about testing it's advised to make a separate module for testing.
So I did that:
mod lol {
pub fn func_a() -> u8 {
func_b()
}
fn func_b() -> u8 {
1
}
}
fn main() {
println!("{}", lol::func_a());
}
#[cfg(test)]
mod tests {
use super::lol::*;
// Works
#[test]
fn test_a() {
assert_eq!(func_a(), 1);
}
//Doesn't work cause private
#[test]
fn test_b() {
assert_eq!(func_b(), 1);
}
}
But this doesn't work because I can't access the private functions I want to test. Because I have a lot of complex private functions, I'd like to test those as well.
What is the best and most idiomatic way to do this? Just writing test-functions in the module lol
for the private functions? Or using documentation test? I by the way have the weird scenario that in my real code the documentation tests do not get executed when running cargo test
.
Thanks.