Crate test4a

Source
Expand description

Testing library that provides some tools to apply “Advanced” Arrange-Act-Assert testing design.

§Examples

use test4a::{Equal, Message, PanicWhen, Runner};

// Definition of the structure that contains expected values.
struct Expected {
    value: usize,
}

// Definition of the "act" methods.
fn add_0(message: &mut Message, value: &mut usize) {
    message.set("Add 0 to the initial integer");
    *value += 0;
}

fn add_1(message: &mut Message, value: &mut usize) {
    message.set("Add 1 to the initial integer");
    *value += 1;
}

fn subtract_1(message: &mut Message, value: &mut usize) {
    message.set("Subtract 1 to the initial integer");
    *value -= 1;
}

// Definition of the "assert" methods.
fn expect_value(
    message: &mut Message,
    value: usize,
    expected: Expected,
) -> Equal<usize> {
    message.set("value == expected.value");
    Equal::new(value, expected.value)
}

// Definition of the tests to execute.
#[test]
fn test_zero() {
    Runner::arrange(|message| {
        message.set("Initial value of 0");
        0
    })
    .act(add_0, || Expected { value: 0 })
    .act(add_1, || Expected { value: 1 })
    .act_panic(PanicWhen::Debug, subtract_1)
    .assert(expect_value);
}

#[test]
fn test_other() {
    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(expect_value);
}

Structs§

Contains
Asserts that a value is in a vector.
Equal
Asserts that two values are equal.
False
Asserts that a value is false.
Greater
Asserts that a value is greater than another one.
GreaterEqual
Asserts that a value is greater than or equal to another one.
Less
Asserts that a value is less than another one.
LessEqual
Asserts that a value is less than or equal to another one.
Message
Stores messages for successive steps of a test.
Multiple
Asserts that multiple assertions created from an iterator have succeed.
NotEqual
Asserts that two values are different.
Runner
Describes and runs multiple tests.
True
Asserts that a value is true.

Enums§

PanicWhen
Defines the configurations when a test can panic.

Traits§

Assert
Defines an assertion.