Skip to main content

test

Attribute Macro test 

Source
#[test]
Expand description

#[obs::test] — drop-in replacement for #[test] / #[tokio::test] that installs an InMemoryObserver on the current thread (sync) or current task (async) for the duration of the test. The body’s emits land in a thread-local / task-local handle that obs::test::assert_emitted! reads.

Sync example:

#[obs::test]
fn login_emits_event() -> anyhow::Result<()> {
    login("alice")?;
    obs::test::assert_emitted!(ObsLoggedIn { user: "alice", .. });
    Ok(())
}

Async example:

#[obs::test]
async fn billing_emits_charge_event() -> anyhow::Result<()> {
    charge_card("4242…").await?;
    obs::test::assert_emitted!(ObsChargeAttempted { outcome: "approved", .. });
    Ok(())
}

Spec 60 § 8 + spec 72 § 3.