pub fn in_kunit_test() -> bool
Expand description
Returns whether we are currently running a KUnit test.
In some cases, you need to call test-only code from outside the test case, for example, to create a function mock. This function allows to change behavior depending on whether we are currently running a KUnit test or not.
ยงExamples
This example shows how a function can be mocked to return a well-known value while testing:
fn fn_mock_example(n: i32) -> i32 {
if in_kunit_test() {
return 100;
}
n + 1
}
let mock_res = fn_mock_example(5);
assert_eq!(mock_res, 100);