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>
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>
Sourcepub fn run(self) -> TestReport<'t, Formatter::Error>
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>
impl<'t, Extra, Filter: TestFilter<Extra>, Ignore: TestIgnore<Extra>, PanicHandler, Runner, Formatter: TestListFormatter<'t, Extra>> TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>
Sourcepub fn list(self) -> TestListReport<Formatter::Error>
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>
impl<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter> TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>
Sourcepub fn with_ignore<WithIgnore: TestIgnore<Extra>>(
self,
ignore: WithIgnore,
) -> TestHarness<'t, Extra, Filter, WithIgnore, PanicHandler, Runner, Formatter>
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.
Sourcepub fn with_filter<WithFilter: TestFilter<Extra>>(
self,
filter: WithFilter,
) -> TestHarness<'t, Extra, WithFilter, Ignore, PanicHandler, Runner, Formatter>
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.
Sourcepub fn with_panic_handler<WithPanicHandler: TestPanicHandler<Extra>>(
self,
panic_handler: WithPanicHandler,
) -> TestHarness<'t, Extra, Filter, Ignore, WithPanicHandler, Runner, Formatter>
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.
Sourcepub fn with_runner<WithRunner: TestRunner<'t, Extra>>(
self,
runner: WithRunner,
) -> TestHarness<'t, Extra, Filter, Ignore, PanicHandler, WithRunner, Formatter>
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.
Sourcepub fn with_formatter<WithFormatter>(
self,
formatter: WithFormatter,
) -> TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, WithFormatter>
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.
Sourcepub 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>
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>
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>
fn clone( &self, ) -> TestHarness<'t, Extra, Filter, Ignore, PanicHandler, Runner, Formatter>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more