Skip to main content

test_suite

Attribute Macro test_suite 

Source
#[test_suite]
Expand description

Attribute macro defining suite of unit tests defined as module. The attribute may only be used in a cfg(ktest) context.

Tests are idiomatically modeled as functions, and so modules of such functions make for a natural representation as a test suite.

Tests defined through this attribute are available to be run via k ut.

A test suite module must meet the following criteria:

  • It must have a one-line docstring. This line becomes the description of the suite on the kernel command-line.
  • It must contain at least one test function; it may contain any other items.

A test function must meet the following criteria:

  • It must be annotated with #[test].
  • It too must have a one-line docstring. This line becomes the description of the test on the kernel command-line.
  • It must have a () -> () signature.

A test function should make assertions only using the declarative assert_/expect_ macros defined in the unittest module.

Disabling a test can be done with a further annotation of #[ignore]. Such a test will still be compiled; it just will not contribute test metadata.

ยงExample

/// Brief test suite description.
#[cfg(ktest)]
#[test_suite(name = "optional_name")]
mod my_suite {
    /* non-test items... */

    /// Brief test case description.
    #[test]
    fn my_case() {
        assert_false!(false);
        expect_true!(1 == 1, "expectation with a message");
    }

    /// This test case is currently disabled.
    #[test]
    #[ignore]
    fn my_disabled_case() {...}
}