1
0
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:
Rob Ede
2023-09-10 02:56:48 +01:00
parent e67443f4e8
commit c5a9579193
6 changed files with 22 additions and 18 deletions

View File

@ -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());

View File

@ -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();