Expand description

Usage

Do not forget to modify Cargo.toml with. If you want you can override before_each_test and after_each_test from the TestEnvironment trait. By default these methods are empty.

[[test]]
name = "integration"
path = "integration-tests/main.rs"
harness = false
   use std::future::Future;
   use std::thread;
   use actix_web::{App, HttpResponse, HttpServer, Responder};
   use actix_web::rt::SystemRunner;
   use test_collector_derive::collect_test;
   use test_collector::{log_env_info, TestEnvironment};
   use test_collector::test_runner::TestRunner;

   struct MockTestEnv {
    system: SystemRunner,
   }

   impl TestEnvironment for MockTestEnv {
    fn start(self) -> Self {
        log_env_info(format_args!("Starting environment"));
        thread::spawn(move || {
            actix_web::rt::System::new().block_on(async move {
                HttpServer::new(move || App::new()
                    .service(hello)
                )
                    .bind("127.0.0.1:9090")?
                    .run()
                    .await
            })
        });
        return self;
    }

    fn block_on<F: Future>(&self, fut: F) -> F::Output {
        self.system.block_on(fut)
    }

    fn stop(self) -> Self {
        log_env_info(format_args!("Here You can stop APP, db or any other services"));
        return self;
    }
   }

   #[actix_web::get("/")]
   async fn hello() -> impl Responder {
    HttpResponse::Ok().body("Hello, world!")
   }


   #[test]
   #[should_panic(expected = "Some tests are Failing")]
   fn possible_main() {
    let system = actix_web::rt::System::new();
    let test_runner = TestRunner::new(MockTestEnv{system});
    test_runner.run();
   }

   #[collect_test]
   pub fn sync_test_failing() {
    println!("Executed sync!");
    assert_eq!(true, false);
   }

   #[collect_test(async)]
   pub async fn async_test_success() {
    let client = reqwest::Client::builder()
        .build()
        .expect("error during client build");
    let response = client.get("http://localhost:9090/").send().await;
    assert!(response.is_ok());
   }

Modules

Structs

Traits

Functions