| name | entity_testing |
| description | Testing strategies and infrastructure for game entity behavior in perovskite_game_api. Use when asked to write tests for entities, including animals, minecarts, etc. |
Testing Entity Coroutines
Entity movement logic (EntityCoroutine implementations) is tested with CoroutineTester from
perovskite_server::game_state::entities::entity_test_helpers. It drives the coroutine
synchronously step-by-step inside run_assertions_in_server (which provides the required async
runtime).
use perovskite_server::game_state::entities::entity_test_helpers::CoroutineTester;
use perovskite_server::game_state::entities::MoveQueueType;
fixture.run_assertions_in_server(|gs| {
let start_pos = Vector3::new(0.0, 0.5, 0.0);
let coro = MyCoroutine { ... };
let mut tester = CoroutineTester::new(
Box::pin(coro),
MoveQueueType::SingleMove,
start_pos,
gs,
).or_fail()?;
tester.advance(gs).or_fail()?;
println!("pos={:?} buffer={}s engaged={}",
tester.current_position(),
tester.move_buffer(),
tester.is_engaged(),
);
let final_pos = tester.post_queue_position();
Ok(())
})?;
CoroutineTester::advance must run inside an async runtime because deferred moves call
tokio::runtime::Handle::current().block_on(...). The run_assertions_in_server closure already
satisfies this. The chunks around start_pos are warmed up automatically by each advance call.
See perovskite_game_api/src/animals/mod.rs for a full example (duck_coroutine_smoke).