pub struct E2EScenario<H> { /* private fields */ }Expand description
E2E test scenario builder and executor.
Provides structured E2E testing with step logging, timing, and detailed failure reporting. Automatically captures request/response data on failures.
§Example
use fastapi_core::testing::{E2EScenario, TestClient};
let client = TestClient::new(app);
let mut scenario = E2EScenario::new("User Registration Flow", client);
scenario.step("Visit registration page", |client| {
let response = client.get("/register").send();
assert_eq!(response.status().as_u16(), 200);
});
scenario.step("Submit registration form", |client| {
let response = client
.post("/register")
.json(&serde_json::json!({"email": "test@example.com", "password": "secret123"}))
.send();
assert_eq!(response.status().as_u16(), 201);
});
// Generate report
let report = scenario.report();
println!("{}", report.to_text());Implementations§
Source§impl<H: Handler + 'static> E2EScenario<H>
impl<H: Handler + 'static> E2EScenario<H>
Sourcepub fn new(name: impl Into<String>, client: TestClient<H>) -> Self
pub fn new(name: impl Into<String>, client: TestClient<H>) -> Self
Creates a new E2E scenario.
Sourcepub fn description(self, desc: impl Into<String>) -> Self
pub fn description(self, desc: impl Into<String>) -> Self
Sets the scenario description.
Sourcepub fn stop_on_failure(self, stop: bool) -> Self
pub fn stop_on_failure(self, stop: bool) -> Self
Configures whether to stop on first failure (default: true).
Sourcepub fn client(&self) -> &TestClient<H>
pub fn client(&self) -> &TestClient<H>
Returns a reference to the test client.
Sourcepub fn client_mut(&mut self) -> &mut TestClient<H>
pub fn client_mut(&mut self) -> &mut TestClient<H>
Returns a mutable reference to the test client.
Sourcepub fn step<F>(&mut self, name: impl Into<String>, f: F)
pub fn step<F>(&mut self, name: impl Into<String>, f: F)
Executes a step in the scenario.
The step function receives a reference to the test client and should perform assertions. Panics are caught and recorded as failures.
Sourcepub fn try_step<F, E>(&mut self, name: impl Into<String>, f: F) -> Result<(), E>
pub fn try_step<F, E>(&mut self, name: impl Into<String>, f: F) -> Result<(), E>
Executes a step that returns a result (for more control over error handling).
Sourcepub fn assert_passed(&self)
pub fn assert_passed(&self)
Asserts that the scenario passed, panicking with a detailed report if not.
Call this at the end of your test to ensure all steps passed.