Skip to main content

Module testing

Module testing 

Source
Expand description

Testing utilities for actors.

This module provides a TestHarness for synchronous actor testing without spawning actual tasks or threads.

§Example

#[test]
fn test_counter() {
	struct Counter;

	impl Actor for Counter {
		type State = i64;
		type Message = i64;

		fn init(&self, _ctx: &Context<Self::Message>) -> Self::State {
			0
		}

		fn handle(
			&self,
			state: &mut Self::State,
			msg: Self::Message,
			_ctx: &Context<Self::Message>,
		) -> Directive {
			*state += msg;
			Directive::Continue
		}
	}

	let mut harness = TestHarness::new(Counter);
	harness.send(5);
	harness.send(3);
	harness.process_all();

	assert_eq!(*harness.state(), 8);
}

Structs§

TestHarness
Test harness for synchronous actor testing.