pub struct IntegrationTestBuilder { /* private fields */ }Expand description
Integration test builder
Implementations§
Source§impl IntegrationTestBuilder
impl IntegrationTestBuilder
Sourcepub fn before_each<F, Fut>(self, f: F) -> Self
pub fn before_each<F, Fut>(self, f: F) -> Self
Add before_each hook
Sourcepub fn after_each<F, Fut>(self, f: F) -> Self
pub fn after_each<F, Fut>(self, f: F) -> Self
Add after_each hook
Sourcepub async fn run_test<F, Fut, T>(&self, body: F) -> T
pub async fn run_test<F, Fut, T>(&self, body: F) -> T
Run body with the collected hooks around it: every before_each
hook is awaited (in registration order), then body, then every
after_each hook (in registration order). after_each hooks run
whenever body returns normally; if body panics, the panic
unwinds through this function and after_each hooks do not run
(matching TestFixture::run_test’s non-catching behavior).
§Examples
use armature_testing::integration::IntegrationTestBuilder;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
let order = Arc::new(AtomicUsize::new(0));
let before_slot = order.clone();
let after_slot = order.clone();
let builder = IntegrationTestBuilder::new("example")
.before_each(move || {
let before_slot = before_slot.clone();
async move { before_slot.store(1, Ordering::SeqCst); }
})
.after_each(move || {
let after_slot = after_slot.clone();
async move { after_slot.store(3, Ordering::SeqCst); }
});
let seen_during_body = builder
.run_test(|| async { order.load(Ordering::SeqCst) })
.await;
assert_eq!(seen_during_body, 1); // before_each already ran
assert_eq!(order.load(Ordering::SeqCst), 3); // after_each ran tooAuto Trait Implementations§
impl !RefUnwindSafe for IntegrationTestBuilder
impl !UnwindSafe for IntegrationTestBuilder
impl Freeze for IntegrationTestBuilder
impl Send for IntegrationTestBuilder
impl Sync for IntegrationTestBuilder
impl Unpin for IntegrationTestBuilder
impl UnsafeUnpin for IntegrationTestBuilder
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<R, D> DepsPresent<D> for R
Source§impl<T> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Returns the TypeId of this type (for internal use)
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
Returns the type name for debugging