becheran/ntest

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

Net unit-testing framework documentation

NTest

. Inspired by the .Net unit-testing framework NUnit.

  • documentation
  • library on crates.io

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

License

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

Issues

Collection of the latest Issues

YuhanLiin

YuhanLiin

Comment Icon1

Describe the bug When the timeout attribute is put on a test and that test panics, the test reports that the test timed out, even though it didn't.

To Reproduce Run this code:

Results in this output:

The output should instead be this:

Additional context The fix is likely in ntest_proc_macro_helper, which needs to be changed to handle test panics.

phodina

phodina

bug
Comment Icon3

Describe the bug I'm building ntest 0.7.3 crate for Guix System. The crate itself builds fine. However, when I run the cargo test release the process exits with the SIGILL: illegal instruction.

To Reproduce Steps to reproduce the behavior:

  1. Run guix import crate -r ntest
  2. Store definitions in <guix_repo>/guix/packages/crates-io.scm
  3. Build the package guix build -L <guix_repo> rust-ntest
  4. See error

Expected behavior The test would pass.

Screenshots Here is a backtrace of running in gdb

Also as the tests run in parallel I tried to narrow down the issue with running them sequentially:

RUST_TEST_THREADS=1 cargo test --release
running 6 tests
test no_timeout ... ok
test test_function_10 ... ok
test test_function_200 ... ok
test timeout ... ok
test timeout_inf_loop ... error: test failed, to rerun pass '--test integration'

Caused by: process didn't exit successfully: /tmp/guix-build-rust-ntest<span class="hljs-string">-0</span>.7.3.drv<span class="hljs-string">-0</span>/ntest<span class="hljs-string">-0</span>.7.3/target/release/deps/integration<span class="hljs-string">-364</span>ecb9c23d58916 (signal: 4, SIGILL: illegal instruction) ``

Desktop (please complete the following information):

  • Guix System
becheran

becheran

Comment Icon0

When using two attributes such as test case and timeout they will check for the next attribute to be valid. #[test_case(200)] #[ntest::timeout(100)] Will panic: error: custom attribute panicked --> ntest/tests/integration.rs:5:1 | 5 | #[test_case(200)] | ^^^^^^^^^^^^^^^^^ | = help: message: Expected identifier!

Information - Updated Aug 07, 2022

Stars: 18
Forks: 1
Issues: 5

Repositories & Extras

Rust library for Self Organising Maps (SOM)

Add rusticsom as a dependency in Cargo

Rust library for Self Organising Maps (SOM)

Rust library for parsing configuration files

The 'option' can be any string with no whitespace

Rust library for parsing configuration files

Rust library for the Pimoroni Four Letter pHAT

This library aims to port ht16k33 (or rather a fork, as of right now) so credit goes to ht16k33-diet

Rust library for the Pimoroni Four Letter pHAT

Rust library for emulating 32-bit RISC-V

This library can execute instructions against any memory and register file that implements

Rust library for emulating 32-bit RISC-V

Rust library for connecting to the IPFS HTTP API using Hyper/Actix

You can use actix-web as a backend instead of hyper

Rust library for connecting to the IPFS HTTP API using Hyper/Actix

Rust library to manipulate file system access control lists (ACL) on macOS, Linux, and FreeBSD

This module provides two high level functions, getfacl and setfacl

Rust library to manipulate file system access control lists (ACL) on macOS, Linux, and FreeBSD

Rust library translation (rust-src/rust-std/stdlib/rustlib translation)

This is the place to translate Having a documentation in your native language is essential if you don't speak English, and still enjoyable even if...

Rust library translation (rust-src/rust-std/stdlib/rustlib translation)

Rust library for using Infrared hardware decoders (For example a Vishay TSOP* decoder),

enabling remote control support for embedded project

Rust library for using Infrared hardware decoders (For example a Vishay TSOP* decoder),

Rust library for interaction with the OriginTrail Decentralized Knowledge Graph

open up an issue on this repository and let us know

Rust library for interaction with the OriginTrail Decentralized Knowledge Graph

Rust library for parsing COLLADA files

Notice: This library is built around files exported from Blender 2

Rust library for parsing COLLADA files

web-library-rust

A basic CRUD application that represents books in a library

web-library-rust
Facebook Instagram Twitter GitHub Dribbble
Privacy