Expand description
Testing helpers, in the spirit of Laravel’s HTTP tests.
use renox::testing::TestApp;
#[renox::test]
async fn creating_a_product() {
let app = TestApp::new(shop::app()).await; // in-memory DB, migrated
let user = User::register(app.db(), "Alex", "alex@example.com", "secret123").await.unwrap();
app.acting_as(&user)
.post("/products", &[("name", "Coffee"), ("price", "18000")])
.await
.assert_redirect("/products");
app.assert_database_has("products", &[("name", &"Coffee")]).await;
app.get("/products").await.assert_ok().assert_see("Coffee");
}A TestApp runs the app’s router in memory with a test configuration:
an in-memory SQLite database with all migrations run, the memory mail
driver, no background workers or scheduler, storage in a temporary
directory, and the app’s own resources/ and public/ directories. It
keeps the session cookie between requests like a browser and sends the
CSRF token itself, so tests read like user actions.
Structs§
- TestApp
- The app under test, with a browser-like client.
- Test
Request - A request being built:
app.request().header("accept", "application/json").get(..). - Test
Response - A response with Laravel-style assertions; they panic with the status and
the start of the body, and return
&Selfso they can be chained.