Conventionally, unit tests in Rust are given a separate module, which is conditionally compiled with #[cfg(test)]
:
#[cfg(test)]
mod tests {
#[test]
fn test1() { ... }
#[test]
fn test2() { ... }
}
However, I've been using a style where tests are more inline:
pub fn func1() {...}
#[cfg(test)]
#[test]
fn test_func1() {...}
pub fn func2() {...}
#[cfg(test)]
#[test]
fn test_func2() {...}
My question is, does #[test]
imply #[cfg(test)]
? That is, if I tag my test functions with #[test]
but not #[cfg(test)]
, will they still be correctly absent in non-test builds?
Aucun commentaire:
Enregistrer un commentaire