utmt 0.7.0

Unit Test Macros. Several tools and macro for unit test improving.
Documentation

UTMT - Unit Tests Macros (for Tests)

Goal

The goal of this project is to create new macros for unit tests improving.

Features

This project provides the following features.

assert_all(...)

This macro allows to set several assertion in a single assertion like AssertAll(...) of the excellent JUnit 5.x test framework for Java.

The number of assertion rules is unlimited.

Examples

invalid assertions

assert_all!(1+1==2, 2+3==4, 'a' == 'b', 1 == 1);

With this example above, we can see that the second and third assertions are false. The assert_all!(...) macro will test all assertions first, and store the false assertion for a final report. While all assertions are done, the assert_all!(...) shows the final results by indicating:

  • the false assertions list,
  • the number of false assertions,
  • run a panic! macro to inform the unittest rust framework that this test is failed.

valid assertions

assert_all!(true, 2+3 == 5, 'a' == 'a');

setup!({...})

This macro is corresponding to the setUp() method of the JUnit framework like. But the difference is the setup!() must be implemented in each test method first.

teardown!({...})

This macro is corresponding to the tearDown() method of the JUnit framework like. But the difference is the teardown!() must be implemented in each test method first.

Examples

#[test]
    fn test_setup_teardown() {
        setup!({
            File::create(Path::new("test.txt")).unwrap();
        });
        teardown!({
            fs::remove_file(Path::new("test.txt")).unwrap();
        });

        assert!(Path::new("test.txt").exists());
    }

The setup!({...}) block will be executed first. But the teardown!({...}) will be delayed while the assert!(...) macro have been executed. The teardown({...}) will ensure to be executed whatever the assert!(...) result.

assert_slices_eq!(...) and assert_slices_ne!(...)

These macros compare 2 slices and panic only if these slices are equals for the first macro or not equals for the second one. The content, size and order are importants.

Examples

  • For assert_slices_eq!(...):

valid assertion

assert_slices_eq!([1,2,3,4,5], [1,2,3,4,5]);

invalid assertion

assert_slices_eq!([1,2,3,4,5], [5,4,3,2,1]);
  • For assert_slices_ne!(...):

valid assertion

assert_slices_ne!([1,2,3,4,5], [5,4,3,2,1]);

invalid assertion

assert_slices_ne!([1,2,3,4,5], [1,2,3,4,5]);

assert_same_slices!(...) and assert_not_same_slices!(...)

These macros compare 2 slices and panic only if these slices haven't got the same content first the first macro, or same content for the second one. Same content, means same values, same size but the order is not taking account.

Examples

  • For assert_same_slices!(...):

valid assertion

assert_same_slices!([1,2,3,4,5], [5,3,4,1,2]);

invalid assertion

assert_same_slices!([1,2,3,4,5], [6,7,8,9,10]);
  • For assert_not_same_slices!(...):

valid assertion

assert_not_same_slices!([1,2,3,4,5], [1,2,3]);

invalid assertion

assert_not_same_slices!([1,2,3,4,5], [5,4,3,2,1]);

Other features

See the utmt documentation on utmt.

Authors and acknowledgement

Help will be appreciated. All tools will be developed with rust technology. If you have new ideas, your welcome!

License

This project is under MIT licence.

Project status

This project is under development and all contributions are welcome.

These tools are provided without any guaranties.