Crates.io | ntest |
lib.rs | ntest |
version | 0.9.3 |
source | src |
created_at | 2019-08-10 13:59:52.996587 |
updated_at | 2024-06-19 05:30:17.637108 |
description | Testing framework for rust which enhances the built-in library with some useful features. |
homepage | |
repository | https://github.com/becheran/ntest |
max_upload_size | |
id | 155601 |
size | 16,712 |
Testing framework for rust which enhances the built-in library with some useful features. Inspired by the .Net unit-testing framework NUnit.
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 = "*"
#[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.
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);
}
use ntest::timeout;
#[test]
#[timeout(10)]
#[should_panic]
fn timeout() {
loop {};
}
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);
}