How to write test in rust

Question:
Hi can someone help me write test for my rust code
here is how my file structure looks like

src/
  main.rs
  moods.rs
tests/
  main_test.rs

main.rs

mod moods;

fn main () {
    println!("Add: {}",moods::add(2,3))
}

moods.rs

pub fn add(a: i32, b: i32) -> i32 {
	a + b
}

main_test.rs

use crate::moods::add;

#[test]
fn check_add(){
	assert_eq!(add(2,3),5)
}

Error

error[E0432]: unresolved import `crate::moods`
 --> tests/main_test.rs:1:12
  |
1 | use crate::moods::add;
  |            ^^^^^ could not find `moods` in the crate root

Can someone help me understand why is this error coming??

1 Like

This code is running it gives the output.
Not sure why it giving error on cargo test.