Expand description
A mocked version of the embassy-executor crate.
§Examples
use embassy_mock::executor::Spawner;
#[embassy_executor::task]
async fn example_task() {}
// Generic over the `Spawner` trait
pub fn spawn_tasks<S: Spawner>(spawner: &S) {
spawner.spawn(example_task()).unwrap();
}
// The real main that runs on the Embassy executor.
// #[embassy_executor::main]
// async fn main(spawner: embassy_executor::Spawner) {
// spawn_tasks(&spawner);
// }
// The unit tests that use the `MockSpawner`.
#[cfg(test)]
mod tests {
use super::*;
use embassy_mock::executor::MockSpawner;
#[test]
fn test_spawning_of_tasks() {
let spawner = MockSpawner::expect(1);
spawn_tasks(&spawner);
assert_eq!(spawner.done(), Ok(()));
}
}Structs§
- Mock
Spawner - A mocked version of
embassy_executor::Spawnerthat can be used in its place for unit tests.
Enums§
- Mock
Spawner Error - The errors that are reported by
MockSpawner.
Traits§
- Spawner
- The trait to replace the
embassy_executor::Spawnerin code to allow theMockSpawnerto be used in its place for tests.