I just wanted to separate this example in different files
project/src/main.rs
#[cfg(test)] mod tests;
#[macro_use] extern crate rocket;
#[get("/")]
fn index() -> &'static str {
"Hello, world!"
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index])
}
and project/tests/main.rs
#[macro_use] extern crate rocket;
#[cfg(test)]
mod test {
use super::rocket;
use rocket::local::Client;
use rocket::http::Status;
#[test]
fn hello_world() {
let client = Client::new(rocket()).expect("valid rocket instance");
let mut response = client.get("/").dispatch();
assert_eq!(response.status(), Status::Ok);
assert_eq!(response.body_string(), Some("Hello, world!".into()));
}
}
But I'm getting the following error
❯ cargo test
Compiling jedi_archives v0.0.0 (/home/user/sync/code/rust/jedi_archives)
error[E0583]: file not found for module `tests`
--> src/main.rs:1:14
|
1 | #[cfg(test)] mod tests;
| ^^^^^^^^^^
|
= help: to create the module `tests`, create file "src/tests.rs" or "src/tests/mod.rs"
error[E0432]: unresolved import `rocket::local::Client`
--> tests/main.rs:6:9
|
6 | use rocket::local::Client;
| ^^^^^^^^^^^^^^^------
| | |
| | help: a similar name exists in the module (notice the capitalization): `client`
| no `Client` in `local`
error[E0423]: expected function, found crate `rocket`
--> tests/main.rs:11:34
|
11 | let client = Client::new(rocket()).expect("valid rocket instance");
| ^^^^^^ not a function
warning: unused `#[macro_use]` import
--> tests/main.rs:1:1
|
1 | #[macro_use] extern crate rocket;
| ^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
Some errors have detailed explanations: E0423, E0432.
For more information about an error, try `rustc --explain E0423`.
warning: `jedi_archives` (test "main") generated 1 warning
error: could not compile `jedi_archives` due to 2 previous errors; 1 warning emitted
warning: build failed, waiting for other jobs to finish...
For more information about this error, try `rustc --explain E0583`.
error: build failed