testx

Crates.iotestx
lib.rstestx
version0.1.2
sourcesrc
created_at2022-12-20 13:55:30.250456
updated_at2022-12-22 13:08:49.011223
descriptionAn extended Rust testcase
homepage
repositoryhttps://github.com/drobin/testx-rs.git
max_upload_size
id742349
size18,717
Robin Doer (drobin)

documentation

https://docs.rs/testx

README

testx-rs: An extended Rust testcase

The testx crate provides the testx macro, which is an extended version of the Rust test macro. The key features are:

  • The testx macro is fully compatible for the Rust test macro, all tests maked with #[testx] (instead of #[test]) are executed with cargo-test.
  • Support for a test preparation function.

Getting started

Create a testx testcase

Mark the testcase with #[testx]. Calling cargo test will execute the testcase.

use testx::testx;

#[testx]
fn sample() {
   assert_eq!(1, 1);
}

// output:
// running 1 test
// test sample ... ok

Prepare data for a testcase with a setup function

Provide a function setup which prepares and returns some data for your testcase. Next, your testcase needs one argument, which must match the return value of the setup function.

A testcase marked with #[testx] will first execute the setup function and will pass its return value to your testcase.

use testx::testx;

fn setup() -> u32 {
    4711
}

#[testx]
pub fn sample(num: u32) {
    assert_eq!(num, 4711);
}

Installation

Put the following line into the [dev-dependencies] section of your Cargo.toml:

[dev-dependencies]
testx = "0.1.2"
Commit count: 7

cargo fmt