rs_unit

Crates.iors_unit
lib.rsrs_unit
version0.0.2
sourcesrc
created_at2021-10-10 10:03:52.229607
updated_at2021-10-14 19:05:56.856649
descriptionRsUnit is a testing crate similar to Elixirs ExUnit.
homepage
repositoryhttps://github.com/mawilms/rs-unit
max_upload_size
id463078
size21,371
Marius Wilms (mawilms)

documentation

README

RsUnit

GitHub issues Cargo Downloads Cargo Latest version

RsUnit is a unit testing framework for Rust. It's a wrapper around the native cargo test interface. RsUnit mimics the structure and behavior of ExUnit.

Structure

A test suite is always wrapped in a rs_unit block. Inside this rs_unit block can be multiple describe blocks. A describe block is used to group related tests. The essence of RsUnit is the describe block. This block consists of three parts; a setup, test and teardown part. The setup and teardown are optional. The only required part is test.

Setup

The setup block contains logic that is run before the tests. Here we differentiate between setup and setup_all. The setup block is run with every test. The setup_all block is executed a single time, before every test. Database or drive setups are use cases for the setup block.

Test

Each describe block contain multiple test blocks. There is no limit but keep in mind to keep your tests as short as possible.

Teardown

The teardown block is run after the tests. Similar to the setup blocks, you have the choice between teardown and teardown_all. A typical use case is for example the removal of the database or folders that were created in the setup block.

Example

use rs_unit::rs_unit;

pub fn add_number(number_one: i32, number_two: i32) -> i32 {
    number_one + number_two
}

rs_unit! {
    describe "add_number/2" {
        test "success: Add two numbers" {
            let result = add_number(1, 1);

            assert_eq!(result, 2);
        }
    }
}

Special thanks

I want to thank NyxCode and Yandros FR-ES from Discord and rodrimati1992 for helping me to better understand how procedural macros are working, having patience and pointing me into the right direction.

License

MIT License - Copyright (c) 2021 Marius Wilms

Commit count: 10

cargo fmt