Skip to main content

TestHarness

Struct TestHarness 

Source
pub struct TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter> { /* private fields */ }
Expand description

A configurable test harness.

TestHarness is the main operator of Kitest. It holds the full test list and all strategies that define how a test run behaves: filtering, ignoring, panic handling, running, and formatting.

A harness is lazy. Constructing it does not do anything by itself. To actually do work, call either run to execute tests or list to list tests.

§Configuration

A harness is configured by chaining with_* methods. Each with_* call replaces exactly one strategy and returns a new TestHarness with an updated generic type. This keeps the configuration type safe and avoids runtime indirection.

To enable grouping, call with_grouper. This promotes the harness into a GroupedTestHarness. From that point on, tests are executed through groups and group specific strategies can be configured.

§Generics and type inference

The type of a fully configured harness can look intimidating in rustdoc because it carries a generic parameter for each strategy. In normal usage you rarely have to write these types explicitly. Type inference will figure them out from the strategies you keep or replace.

§Lifetimes

The lifetime parameter 't is the lifetime of the test slice stored in the harness. All strategies are allowed to borrow from the tests through 't, which avoids unnecessary allocations and copying.

Implementations§

Source§

impl<'t, Extra: RefUnwindSafe + Sync, Filter: TestFilter<Extra>, Ignore: TestIgnore<Extra> + Send + Sync + 't, PanicHandler: TestPanicHandler<Extra> + Send + Sync + 't, Runner: TestRunner<'t, Extra>, Formatter: TestFormatter<'t, Extra> + 't> TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>

Source

pub fn run(self) -> TestReport<'t, Formatter::Error>

Execute the test harness and produce a TestReport.

This runs the full test pipeline:

  • filters tests
  • applies ignore rules
  • executes tests through the runner
  • captures output and panics
  • forwards events to the formatter

The harness is consumed by this call. After running, the result is returned as a TestReport, which can be converted into an exit status.

Formatting errors are collected and included in the report instead of aborting the run early.

Source§

impl<'t, Extra, Filter: TestFilter<Extra>, Ignore: TestIgnore<Extra>, PanicHandler, Runner, Formatter: TestListFormatter<'t, Extra>> TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>

Source

pub fn list(self) -> TestListReport<Formatter::Error>

List tests without executing them.

This runs the harness in listing mode. Tests are filtered and ignored in the same way as during a normal run, but test functions are never executed.

The formatter is notified of listing events and may print a test overview similar to cargo test -- --list.

The harness is consumed by this call.

Source§

impl<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter> TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>

Source

pub fn with_ignore<WithIgnore: TestIgnore<Extra>>( self, ignore: WithIgnore, ) -> TestHarness<'t, Extra, Filter, WithIgnore, PanicHandler, Runner, Formatter>

Replace the ignore strategy.

The ignore strategy decides whether a test is executed or reported as ignored, optionally with a reason.

This does not remove tests from the harness. Ignored tests are still visible to formatters and listing mode.

Source

pub fn with_filter<WithFilter: TestFilter<Extra>>( self, filter: WithFilter, ) -> TestHarness<'t, Extra, WithFilter, Ignore, PanicHandler, Runner, Formatter>

Replace the filter strategy.

The filter strategy decides which tests participate in the run at all. Filtered tests are removed before execution and are not passed to the runner.

Filtering happens before ignoring.

Source

pub fn with_panic_handler<WithPanicHandler: TestPanicHandler<Extra>>( self, panic_handler: WithPanicHandler, ) -> TestHarness<'t, Extra, Filter, Ignore, WithPanicHandler, Runner, Formatter>

Replace the panic handler.

The panic handler is responsible for executing the test function and converting panics into a TestStatus, taking metadata such as should_panic into account.

Source

pub fn with_runner<WithRunner: TestRunner<'t, Extra>>( self, runner: WithRunner, ) -> TestHarness<'t, Extra, Filter, Ignore, PanicHandler, WithRunner, Formatter>

Replace the test runner.

The runner controls how tests are scheduled and executed, for example sequentially or in parallel.

Runners receive prepared test closures and are responsible for driving execution and returning outcomes.

Source

pub fn with_formatter<WithFormatter>( self, formatter: WithFormatter, ) -> TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, WithFormatter>

Replace the formatter.

The formatter receives structured events describing the test run and is responsible for producing output.

This includes progress reporting, test results, and final summaries.

Source

pub fn with_grouper<WithGrouper: TestGrouper<Extra, GroupKey, GroupCtx>, GroupKey, GroupCtx>( self, grouper: WithGrouper, ) -> GroupedTestHarness<'t, Extra, GroupKey, GroupCtx, Filter, WithGrouper, TestGroupHashMap<'t, Extra, GroupKey>, Ignore, SimpleGroupRunner, PanicHandler, Runner, Formatter>

Enable grouping and promote this harness into a GroupedTestHarness.

Calling this method switches the execution model from individual tests to test groups. Tests are assigned to groups using the provided TestGrouper, and all execution happens through those groups.

This is a type level transition. Once grouping is enabled, group specific strategies such as group runners and grouped formatters become available.

Trait Implementations§

Source§

impl<'t, Extra: Clone, Filter: Clone, Ignore: Clone, PanicHandler: Clone, Runner: Clone, Formatter: Clone> Clone for TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>

Source§

fn clone( &self, ) -> TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'t, Extra: Debug, Filter: Debug, Ignore: Debug, PanicHandler: Debug, Runner: Debug, Formatter: Debug> Debug for TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter> Freeze for TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>
where Filter: Freeze, Ignore: Freeze, PanicHandler: Freeze, Runner: Freeze, Formatter: Freeze,

§

impl<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter> RefUnwindSafe for TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>
where Filter: RefUnwindSafe, Ignore: RefUnwindSafe, PanicHandler: RefUnwindSafe, Runner: RefUnwindSafe, Formatter: RefUnwindSafe, Extra: RefUnwindSafe,

§

impl<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter> Send for TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>
where Filter: Send, Ignore: Send, PanicHandler: Send, Runner: Send, Formatter: Send, Extra: Sync,

§

impl<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter> Sync for TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>
where Filter: Sync, Ignore: Sync, PanicHandler: Sync, Runner: Sync, Formatter: Sync, Extra: Sync,

§

impl<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter> Unpin for TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>
where Filter: Unpin, Ignore: Unpin, PanicHandler: Unpin, Runner: Unpin, Formatter: Unpin,

§

impl<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter> UnsafeUnpin for TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>
where Filter: UnsafeUnpin, Ignore: UnsafeUnpin, PanicHandler: UnsafeUnpin, Runner: UnsafeUnpin, Formatter: UnsafeUnpin,

§

impl<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter> UnwindSafe for TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>
where Filter: UnwindSafe, Ignore: UnwindSafe, PanicHandler: UnwindSafe, Runner: UnwindSafe, Formatter: UnwindSafe, Extra: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.