mirror of
https://github.com/actix/actix-website
synced 2025-06-27 15:39:02 +02:00
update testing docs to give less precedence to unit testing
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
use actix_web::{HttpRequest, Responder};
|
||||
use actix_web::{get, HttpRequest, Responder};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[get("/")]
|
||||
async fn index(_req: HttpRequest) -> impl Responder {
|
||||
"Hello world!"
|
||||
}
|
||||
@ -8,13 +9,13 @@ async fn index(_req: HttpRequest) -> impl Responder {
|
||||
// <integration-one>
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::{http::header::ContentType, test, web, App};
|
||||
use actix_web::{http::header::ContentType, test, App};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_index_get() {
|
||||
let app = test::init_service(App::new().route("/", web::get().to(index))).await;
|
||||
let app = test::init_service(App::new().service(index)).await;
|
||||
let req = test::TestRequest::default()
|
||||
.insert_header(ContentType::plaintext())
|
||||
.to_request();
|
||||
@ -24,7 +25,7 @@ mod tests {
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_index_post() {
|
||||
let app = test::init_service(App::new().route("/", web::get().to(index))).await;
|
||||
let app = test::init_service(App::new().service(index)).await;
|
||||
let req = test::TestRequest::post().uri("/").to_request();
|
||||
let resp = test::call_service(&app, req).await;
|
||||
assert!(resp.status().is_client_error());
|
||||
|
@ -1,4 +1,4 @@
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
@ -7,6 +7,7 @@ struct AppState {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[get("/")]
|
||||
async fn index(data: web::Data<AppState>) -> impl Responder {
|
||||
HttpResponse::Ok().json(data.get_ref())
|
||||
}
|
||||
@ -22,7 +23,7 @@ mod tests {
|
||||
let app = test::init_service(
|
||||
App::new()
|
||||
.app_data(web::Data::new(AppState { count: 4 }))
|
||||
.route("/", web::get().to(index)),
|
||||
.service(index),
|
||||
)
|
||||
.await;
|
||||
let req = test::TestRequest::get().uri("/").to_request();
|
||||
|
Reference in New Issue
Block a user