Boot the real application in a test.
TestApp runs your application in-process: requests go through the real router, middleware and controllers, and assertions chain on the response.
What you get
app.get(…),post,put,patch,delete, with tokens and headers.assert_ok,assert_json_path,assert_json_missing,assert_header— chained.- Fakes:
Dispatcher::fake(),QueueManager::fake(),Mailer::fake(),Http::fake(). - Model factories:
User::factory(). - Every reported failure is visible:
app.reported_of::<F>(),assert_nothing_reported().
In the docs
tests/feature.rs
use app::{boot, Mode};
use rainier_framework::prelude::*;
use rainier_framework::testing::TestApp;
#[tokio::test]
async fn publishing_queues_the_authors_notification() -> Result<()> {
let app = TestApp::new(boot(Mode::Testing).await?)?;
app.instance(QueueManager::fake());
app.get("/health").await.assert_ok().assert_json_path("database.status", "ok");
app.get("/api/posts").await.assert_ok().assert_json_path("data.0.title", "Hello");
Queue::instance().assert_pushed::<NotifyAuthor>();
app.assert_nothing_reported();
Ok(())
}
Up close
Select an image to see it full size.