[−][src]Struct test4a::Runner
Describes and runs multiple tests.
Examples
use test4a::{Message, Equal, Runner, PanicWhen}; fn add_0(message: &mut Message, value: &mut usize) { message.set("Add 0"); *value += 0; } fn add_1(message: &mut Message, value: &mut usize) { message.set("Add 1"); *value += 1; } fn subtract_1(message: &mut Message, value: &mut usize) { message.set("Subtract 1"); *value -= 1; } fn value_expected( message: &mut Message, value: usize, expected: Expected, ) -> Equal<usize> { message.set("Value is expected"); Equal::new(value, expected.value) } struct Expected { value: usize } // Test #1 Runner::arrange(|message| { message.set("Initial value of 1"); 1 }) .act(add_0, || Expected { value: 1 }) .act(add_1, || Expected { value: 2 }) .act(subtract_1, || Expected { value: 0 }) .assert(value_expected); // Test #2 Runner::arrange(|message| { message.set("Initial value of 42"); 42 }) .act(add_0, || Expected { value: 42 }) .act(add_1, || Expected { value: 43 }) .act(subtract_1, || Expected { value: 41 }) .assert(value_expected); // ...
Methods
impl<'a, T, E> Runner<'a, T, E>
[src]
pub fn arrange(function: impl Fn(&mut Message) -> T + 'a) -> Self
[src]
Constructor.
function
defines how the value to test should be initialized.
It isn't called immediately, but only for each defined test.
pub fn act(
&mut self,
action: impl Fn(&mut Message, &mut T) + 'a,
expectation: impl Fn() -> E + 'a
) -> &mut Self
[src]
&mut self,
action: impl Fn(&mut Message, &mut T) + 'a,
expectation: impl Fn() -> E + 'a
) -> &mut Self
Define an action to execute after the value to test has been created.
The Arrange step is executed before each defined Act step to have independent tests.
pub fn act_panic(
&self,
when: PanicWhen,
function: impl Fn(&mut Message, &mut T) + 'a
) -> &Self
[src]
&self,
when: PanicWhen,
function: impl Fn(&mut Message, &mut T) + 'a
) -> &Self
Define an action that should panic.
The check is done immediately on method call.
The when
parameter allows you to specify when the panic occurs.
For example, integer overflow panics only in debug mode.
pub fn assert<A: Assert>(
&self,
function: impl Fn(&mut Message, T, E) -> A + 'a
) -> &Self
[src]
&self,
function: impl Fn(&mut Message, T, E) -> A + 'a
) -> &Self
Define an assertion to check.
The check is done immediately on method call.
The assertion is tested independently with all defined actions.
pub fn assert_panic<A: Assert>(
&self,
when: PanicWhen,
function: impl Fn(&mut Message, T, E) -> A + 'a
) -> &Self
[src]
&self,
when: PanicWhen,
function: impl Fn(&mut Message, T, E) -> A + 'a
) -> &Self
Defines an assertion that should panic.
The check is done immediately on method call.
The assertion is tested independently with all defined actions.
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,