-
Given the following: #[get("/")]
async fn hello() -> impl Responder {
HttpResponse::Ok()
.content_type("text/plain")
.body("Hello World!")
} Why doesn't this work? #[actix_rt::test]
async fn test_hello_ok() {
let resp = hello().await;
assert_eq!(resp.status(), StatusCode::OK);
} I get the compiler error
Obviously the macro is wrapping/mutating, but the docs make no mention of details. How do I unit test these kinds of endpoints? |
Beta Was this translation helpful? Give feedback.
Answered by
robjtede
Nov 6, 2020
Replies: 1 comment 2 replies
-
You can either use manual routing or something like Edit: alternative is using |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
robjtede
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can either use manual routing or something like
#[cfg_attr(not(test), get("/"))]
to conditionally wrap.Edit: alternative is using
test::init_service
.