Skip to main content

TestHarness

Struct TestHarness 

Source
pub struct TestHarness { /* private fields */ }
Expand description

Minimal test harness for handler dispatch.

Owns a World and auto-advances the sequence number before each dispatch. Designed for unit testing handlers without wiring up real drivers.

§Examples

use nexus_rt::{WorldBuilder, ResMut, IntoHandler, Resource};
use nexus_rt::testing::TestHarness;

#[derive(Resource)]
struct Counter(u64);

fn accumulate(mut counter: ResMut<Counter>, event: u64) {
    counter.0 += event;
}

let mut builder = WorldBuilder::new();
builder.register(Counter(0));
let mut harness = TestHarness::new(builder);

let mut handler = accumulate.into_handler(harness.registry());
harness.dispatch(&mut handler, 10u64);
harness.dispatch(&mut handler, 5u64);

assert_eq!(harness.world().resource::<Counter>().0, 15);

Implementations§

Source§

impl TestHarness

Source

pub fn new(builder: WorldBuilder) -> Self

Build a test harness from a WorldBuilder.

Source

pub fn registry(&self) -> &Registry

Registry access for creating handlers after build.

Source

pub fn dispatch<E>(&mut self, handler: &mut impl Handler<E>, event: E)

Advance sequence and dispatch one event through a handler.

Source

pub fn dispatch_many<E>( &mut self, handler: &mut impl Handler<E>, events: impl IntoIterator<Item = E>, )

Dispatch multiple events sequentially, advancing sequence per event.

Source

pub fn world(&self) -> &World

Read-only world access for assertions.

Source

pub fn world_mut(&mut self) -> &mut World

Mutable world access (e.g. to stamp resources manually).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.