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
impl TestHarness
Sourcepub fn new(builder: WorldBuilder) -> Self
pub fn new(builder: WorldBuilder) -> Self
Build a test harness from a WorldBuilder.
Sourcepub fn dispatch<E>(&mut self, handler: &mut impl Handler<E>, event: E)
pub fn dispatch<E>(&mut self, handler: &mut impl Handler<E>, event: E)
Advance sequence and dispatch one event through a handler.
Sourcepub fn dispatch_many<E>(
&mut self,
handler: &mut impl Handler<E>,
events: impl IntoIterator<Item = E>,
)
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.
Auto Trait Implementations§
impl !Freeze for TestHarness
impl !RefUnwindSafe for TestHarness
impl Send for TestHarness
impl !Sync for TestHarness
impl Unpin for TestHarness
impl UnsafeUnpin for TestHarness
impl UnwindSafe for TestHarness
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more