How do I create a test only module in a separate file

⚓ Rust    📅 2025-11-30    👤 surdeus    👁️ 3      

surdeus

Hey folks,

Every dummy knows that you can add tests this way:

#[cfg(test)]
mod tests {
    use super::*;
    // and so on and so forth
}

I'd like to create a new module containing strings to use in tests like so:

const NO_RESULTS_JSON: &str = r#"
    {
        "total": 0,
        "hits" : [],
    }
    "#;

If that were in a module called test_json.rs how would I mark it so it is only included in the test build, as per the first example?

Thanks again!

3 posts - 2 participants

Read full topic

🏷️ Rust_feed