pub struct SoftAssertions { /* private fields */ }Expand description
Soft assertions collector
Collects multiple assertion failures without stopping test execution.
§Example
let mut soft = SoftAssertions::new();
soft.assert_eq(&1, &2, "values should match");
soft.assert_true(false, "condition should be true");
// Both failures are collected
let result = soft.verify();
assert!(result.is_err());Implementations§
Source§impl SoftAssertions
impl SoftAssertions
Sourcepub fn with_mode(mode: AssertionMode) -> Self
pub fn with_mode(mode: AssertionMode) -> Self
Create with a specific mode
Sourcepub const fn mode(self, mode: AssertionMode) -> Self
pub const fn mode(self, mode: AssertionMode) -> Self
Set the assertion mode
Sourcepub fn assert_eq<T: PartialEq + Debug>(
&mut self,
actual: &T,
expected: &T,
message: &str,
)
pub fn assert_eq<T: PartialEq + Debug>( &mut self, actual: &T, expected: &T, message: &str, )
Assert two values are equal
Sourcepub fn assert_ne<T: PartialEq + Debug>(
&mut self,
actual: &T,
expected: &T,
message: &str,
)
pub fn assert_ne<T: PartialEq + Debug>( &mut self, actual: &T, expected: &T, message: &str, )
Assert two values are not equal
Sourcepub fn assert_true(&mut self, condition: bool, message: &str)
pub fn assert_true(&mut self, condition: bool, message: &str)
Assert a condition is true
Sourcepub fn assert_false(&mut self, condition: bool, message: &str)
pub fn assert_false(&mut self, condition: bool, message: &str)
Assert a condition is false
Sourcepub fn assert_some<T>(&mut self, opt: &Option<T>, message: &str)
pub fn assert_some<T>(&mut self, opt: &Option<T>, message: &str)
Assert a value is Some
Sourcepub fn assert_none<T>(&mut self, opt: &Option<T>, message: &str)
pub fn assert_none<T>(&mut self, opt: &Option<T>, message: &str)
Assert a value is None
Sourcepub fn assert_err<T, E>(&mut self, result: &Result<T, E>, message: &str)
pub fn assert_err<T, E>(&mut self, result: &Result<T, E>, message: &str)
Assert a Result is Err
Sourcepub fn assert_contains(&mut self, haystack: &str, needle: &str, message: &str)
pub fn assert_contains(&mut self, haystack: &str, needle: &str, message: &str)
Assert a string contains a substring
Sourcepub fn assert_len<T>(
&mut self,
collection: &[T],
expected: usize,
message: &str,
)
pub fn assert_len<T>( &mut self, collection: &[T], expected: usize, message: &str, )
Assert a collection has expected length
Sourcepub fn assert_empty<T>(&mut self, collection: &[T], message: &str)
pub fn assert_empty<T>(&mut self, collection: &[T], message: &str)
Assert a collection is empty
Sourcepub fn assert_not_empty<T>(&mut self, collection: &[T], message: &str)
pub fn assert_not_empty<T>(&mut self, collection: &[T], message: &str)
Assert a collection is not empty
Sourcepub fn assert_approx_eq(
&mut self,
actual: f64,
expected: f64,
epsilon: f64,
message: &str,
)
pub fn assert_approx_eq( &mut self, actual: f64, expected: f64, epsilon: f64, message: &str, )
Assert two floats are approximately equal
Sourcepub fn assert_in_range(&mut self, value: f64, min: f64, max: f64, message: &str)
pub fn assert_in_range(&mut self, value: f64, min: f64, max: f64, message: &str)
Assert a value is in a range
Sourcepub fn failures(&self) -> &[AssertionFailure]
pub fn failures(&self) -> &[AssertionFailure]
Get all failures
Sourcepub fn failure_count(&self) -> usize
pub fn failure_count(&self) -> usize
Get the number of failures
Sourcepub const fn assertion_count(&self) -> usize
pub const fn assertion_count(&self) -> usize
Get the total number of assertions checked
Sourcepub fn all_passed(&self) -> bool
pub fn all_passed(&self) -> bool
Check if all assertions passed
Sourcepub fn verify(&self) -> Result<(), SoftAssertionError>
pub fn verify(&self) -> Result<(), SoftAssertionError>
Verify all assertions passed, returning error if any failed
§Errors
Returns error containing all failure messages if any assertions failed
Sourcepub fn summary(&self) -> AssertionSummary
pub fn summary(&self) -> AssertionSummary
Get a summary of the assertions
Trait Implementations§
Source§impl Debug for SoftAssertions
impl Debug for SoftAssertions
Source§impl Default for SoftAssertions
impl Default for SoftAssertions
Source§fn default() -> SoftAssertions
fn default() -> SoftAssertions
Auto Trait Implementations§
impl Freeze for SoftAssertions
impl RefUnwindSafe for SoftAssertions
impl Send for SoftAssertions
impl Sync for SoftAssertions
impl Unpin for SoftAssertions
impl UnsafeUnpin for SoftAssertions
impl UnwindSafe for SoftAssertions
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().