我的代码结构如下。
我运行了“货物运行”并且它有效。但是当我运行“货物测试”时,我得到了如下错误。你能告诉我为什么以及如何解决它们吗?
get
错误:在此范围内找不到属性
routes
错误:在此范围内找不到宏
src/main.rs
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use]
extern crate rocket;
mod common;
fn main() {
common::run();
}
src/common.rs
#[get("/hello")]
pub fn hello() -> &'static str {
"hello"
}
pub fn run() {
rocket::ignite().mount("/", routes![hello]).launch();
}
测试/开发.rs
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use]
extern crate rocket;
#[cfg(test)]
mod common;
#[test]
fn test_development_config() {
common::run();
}
测试/common.rs
use rocket::http::Status;
use rocket::local::Client;
#[get("/check_config")]
fn check_config() -> &'static str {
"hello"
}
pub fn run() {
let rocket = rocket::ignite().mount("/", routes![check_config]);
let client = Client::new(rocket).unwrap();
let response = client.get("/hello").dispatch();
assert_eq!(response.status(), Status::Ok);
}