Run async Rust tests by adding the #[tokio::test] attribute to your async test functions to provide the necessary runtime environment.
Use the #[tokio::test] attribute to run async functions as tests with a runtime.
#[tokio::test]
async fn test_page_title() {
let title = page_title("https://example.com").await;
assert!(title.is_some());
}
Note: Ensure tokio is added to your Cargo.toml dependencies with the test-util feature if needed, or use trpl if your environment relies on it for async support as shown in the source context.
Async code needs a special environment called a 'runtime' to execute, which standard tests don't provide by default. Adding the #[tokio::test] attribute tells the test runner to start this environment automatically before running your test. Think of it like plugging a device into a power strip before turning it on; the test won't work without that power source.