Runner

Struct Runner 

Source
pub struct Runner { /* private fields */ }
Expand description

The main test execution engine for tanu.

Runner is responsible for orchestrating the entire test execution pipeline: test discovery, filtering, concurrent execution, retry handling, event publishing, and result reporting. It supports multiple projects, configurable concurrency, and pluggable reporters.

§Features

  • Concurrent Execution: Tests run in parallel with configurable limits
  • Retry Logic: Automatic retry with exponential backoff for flaky tests
  • Event System: Real-time event publishing for UI integration
  • Filtering: Filter tests by project, module, or test name
  • Reporting: Support for multiple output formats via reporters
  • HTTP Logging: Capture and log all HTTP requests/responses

§Examples

use tanu_core::{Runner, reporter::TableReporter};

let mut runner = Runner::new();
runner.capture_http();
runner.set_concurrency(8);
runner.add_reporter(TableReporter::new());

// Add tests (typically done by procedural macros)
runner.add_test("health_check", "api", test_factory);

// Run all tests
runner.run(&[], &[], &[]).await?;

§Architecture

Tests are executed in separate tokio tasks with:

  • Project-scoped configuration
  • Test-scoped context for event publishing
  • Semaphore-based concurrency control
  • Panic recovery and error handling
  • Automatic retry with configurable backoff

Implementations§

Source§

impl Runner

Source

pub fn new() -> Runner

Creates a new runner with the global tanu configuration.

This loads the configuration from tanu.toml and sets up default options. Use with_config() for custom configuration.

§Examples
use tanu_core::Runner;

let runner = Runner::new();
Source

pub fn with_config(cfg: Config) -> Runner

Creates a new runner with the specified configuration.

This allows for custom configuration beyond what’s in tanu.toml, useful for testing or programmatic setup.

§Examples
use tanu_core::{Runner, Config};

let config = Config::default();
let runner = Runner::with_config(config);
Source

pub fn capture_http(&mut self)

Enables HTTP request/response logging.

When enabled, all HTTP requests made via tanu’s HTTP client will be logged and included in test reports. This is useful for debugging API tests and understanding request/response flow.

§Examples
let mut runner = Runner::new();
runner.capture_http();
Source

pub fn capture_rust(&mut self)

Enables Rust logging output during test execution.

This initializes the tracing subscriber to capture debug, info, warn, and error logs from tests and the framework itself. Useful for debugging test execution issues.

§Examples
let mut runner = Runner::new();
runner.capture_rust();
Source

pub fn terminate_channel(&mut self)

Configures the runner to close the event channel after test execution.

By default, the event channel remains open for continued monitoring. This option closes the channel when all tests complete, signaling that no more events will be published.

§Examples
let mut runner = Runner::new();
runner.terminate_channel();
Source

pub fn add_reporter(&mut self, reporter: impl Reporter + 'static + Send)

Adds a reporter for test output formatting.

Reporters receive test events and format them for different output destinations (console, files, etc.). Multiple reporters can be added to generate multiple output formats simultaneously.

§Examples
use tanu_core::{Runner, reporter::TableReporter};

let mut runner = Runner::new();
runner.add_reporter(TableReporter::new());
Source

pub fn add_boxed_reporter( &mut self, reporter: Box<dyn Reporter + Send + 'static>, )

Adds a boxed reporter for test output formatting.

Similar to add_reporter() but accepts an already-boxed reporter. Useful when working with dynamic reporter selection.

§Examples
use tanu_core::{Runner, reporter::ListReporter};

let mut runner = Runner::new();
let reporter: Box<dyn Reporter + Send> = Box::new(ListReporter::new());
runner.add_boxed_reporter(reporter);
Source

pub fn add_test( &mut self, name: &str, module: &str, factory: Arc<dyn Fn() -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>> + Sync + Send + 'static>, )

Add a test case to the runner.

Source

pub fn set_concurrency(&mut self, concurrency: usize)

Sets the maximum number of tests to run concurrently.

By default, tests run with unlimited concurrency. This setting allows you to limit concurrent execution to reduce resource usage or avoid overwhelming external services.

§Examples
let mut runner = Runner::new();
runner.set_concurrency(4); // Max 4 tests at once
Source

pub async fn run( &mut self, project_names: &[String], module_names: &[String], test_names: &[String], ) -> Result<()>

Executes all registered tests with optional filtering.

Runs tests concurrently according to the configured options and filters. Tests can be filtered by project name, module name, or specific test names. Empty filter arrays mean “include all”.

§Parameters
  • project_names: Only run tests from these projects (empty = all projects)
  • module_names: Only run tests from these modules (empty = all modules)
  • test_names: Only run these specific tests (empty = all tests)
§Examples
let mut runner = Runner::new();

// Run all tests
runner.run(&[], &[], &[]).await?;

// Run only "staging" project tests
runner.run(&["staging".to_string()], &[], &[]).await?;

// Run specific test
runner.run(&[], &[], &["api::health_check".to_string()]).await?;
§Errors

Returns an error if:

  • Any test fails (unless configured to continue on failure)
  • A test panics and cannot be recovered
  • Reporter setup or execution fails
  • Event channel operations fail
Source

pub fn list(&self) -> Vec<&TestInfo>

Returns a list of all registered test metadata.

This provides access to test information without executing the tests. Useful for building test UIs, generating reports, or implementing custom filtering logic.

§Examples
let runner = Runner::new();
let tests = runner.list();

for test in tests {
    println!("Test: {}", test.full_name());
}

Trait Implementations§

Source§

impl Default for Runner

Source§

fn default() -> Runner

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Runner

§

impl !RefUnwindSafe for Runner

§

impl Send for Runner

§

impl !Sync for Runner

§

impl Unpin for Runner

§

impl !UnwindSafe for Runner

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,