[]Attribute Macro aktrs::test

#[test]
This is supported on feature="testkit" only.

Marks a function to be run as an aktrs unit test.

The unit test will be automatically supplied with an actor test kit.

Examples

use aktrs::actor::{self, testkit::ActorTestKit, Behavior};

#[actor::testkit::test]
fn my_simple_test(mut t: ActorTestKit) -> aktrs::Result<()> {
    let mut probe = t.spawn_anonymous_test_probe();
    let pid = probe.pid();

    let mut actor = t.spawn_anonymous(Behaviors::receive_message(move |cx, msg| {
        let mut pid = pid.clone();
        cx.run_side_effect(async move {
            let _ = pid.tell(msg).await;
        });
        Ok(Behaviors::same())
    }));

    let _ = t.block_on(actor.tell("hello, world!"));
    assert_eq!(probe.receive_message(), "hello, world!");

    Ok(())
}