Creating tests in separate directory

⚓ Rust    📅 2025-09-13    👤 surdeus    👁️ 12      

surdeus

Warning

This post was published 129 days ago. The information described in this article may have changed.

So I have a module I am creating called: "etimer_unix"
I created it with 'cargo new --lib etimer_unix'
The Cargo.toml file has an entry like this:

[package]
name="etimer_unix"


I have src directory where I have my implementation
I have a file called src/lib.rs, and it contains 1 function declared as follows:

#[allow(non_snake_case)]
pub extern "C" fn ETIMER_getNow() -> u32 {
  // implementation details omitted
  return 42;
}

I have a test directory where I have my separate test files.
I have a file named: tests/test_get_now.rs which has this:

use std::{thread,time};
use ETIMER_UNIX::*;  /* WHAT SHOULD THIS BE??? */

#[test]
fn test_getnow_msecs() // cspell: words getnow, mess
{
    let start = ETIMER_getNow(); // cspell: words ETIMER
    // and other things committed here
}

When I build the module using "cargo build" - it builds with no warnings
When I try to build for test, ie: 'cargo test' I get the error:

error[E0432]: unresolved import `ETIMER_UNIX'

I have tried the capitalization schemes none of these work.

I think the problem is in my 'test_get_now.rs' I need to import the DUT module but that's not working and I'm evidently doing it wrong.


The closest example I can find is this - but this is as if the test is using some other module, not the current active module

1 post - 1 participant

Read full topic

🏷️ Rust_feed