#test #tests #unit #testing

dev ntest

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

26 releases

0.7.2 Nov 3, 2020
0.7.1 May 24, 2020
0.6.0 Mar 6, 2020
0.4.1 Dec 29, 2019
0.3.3 Sep 20, 2019

#38 in Testing

Download history 174/week @ 2020-08-13 149/week @ 2020-08-20 192/week @ 2020-08-27 177/week @ 2020-09-03 183/week @ 2020-09-10 152/week @ 2020-09-17 142/week @ 2020-09-24 125/week @ 2020-10-01 126/week @ 2020-10-08 133/week @ 2020-10-15 155/week @ 2020-10-22 186/week @ 2020-10-29 419/week @ 2020-11-05 599/week @ 2020-11-12 821/week @ 2020-11-19 977/week @ 2020-11-26

657 downloads per month
Used in less than 6 crates

MIT license

18KB
295 lines

NTest

Build Status

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);
}

Changelog

Checkout the changelog file to see the changes between different versions.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependencies

~0.8–1.4MB
~32K SLoC