#unit-testing #test-framework #unit

dev ntest

Testing framework for rust which enhances the built-in library with some useful features

35 releases

0.9.3 Jun 19, 2024
0.9.2 Mar 8, 2024
0.9.0 Nov 11, 2022
0.8.1 Jun 6, 2022
0.3.3 Sep 20, 2019

#21 in Testing

Download history 35100/week @ 2024-08-05 30503/week @ 2024-08-12 57527/week @ 2024-08-19 29501/week @ 2024-08-26 30002/week @ 2024-09-02 28289/week @ 2024-09-09 24493/week @ 2024-09-16 25850/week @ 2024-09-23 31346/week @ 2024-09-30 36418/week @ 2024-10-07 29238/week @ 2024-10-14 30361/week @ 2024-10-21 31441/week @ 2024-10-28 23522/week @ 2024-11-04 26131/week @ 2024-11-11 24192/week @ 2024-11-18

106,295 downloads per month
Used in 66 crates

MIT license

17KB
270 lines

NTest

docs crates downloads build status license

Testing framework for rust which enhances the built-in library with some useful features. Inspired by the .Net unit-testing framework NUnit.

Getting Started

Some functions of NTest use procedural macros which are stable for rust edition 2018. If you use the library make sure that you are using the 2018 version of rust. Update the Cargo.toml file:

[package]
edition = "2018"
# ..

Add the NTest library to your developer dependencies in the Cargo.toml file:

[dev-dependencies]
ntest = "*"

Content

  • #[timeout()] Attribute used for timeouts in tests.
  • #[test_case()] Attribute used to define multiple test cases for a test function.
  • assert_about_equal!() Compare two floating point values or vectors for equality.
  • assert_false!() Expects false argument for test case.
  • assert_true!() Expects true argument for test case.
  • assert_panics!() Expects block to panic. Otherwise the test fails.

For more information read the documentation.

Examples

Create test cases

use ntest::test_case;

#[test_case("https://doc.rust-lang.org.html")]
#[test_case("http://www.website.php", name="important_test")]
fn test_http_link_types(link: &str) {
    test_link(link, &LinkType::HTTP);
}

Timeout for long running functions

use ntest::timeout;

#[test]
#[timeout(10)]
#[should_panic]
fn timeout() {
    loop {};
}

Combine attributes

use std::{thread, time};
use ntest::timeout;
use ntest::test_case;

#[test_case(200)]
#[timeout(100)]
#[should_panic]
#[test_case(10)]
#[timeout(100)]
fn test_function(i : u32) {
    let sleep_time = time::Duration::from_millis(i);
    thread::sleep(sleep_time);
}

Dependencies

~3MB
~61K SLoC