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
impl Runner
Sourcepub fn with_config(cfg: Config) -> Runner
pub fn with_config(cfg: Config) -> Runner
Sourcepub fn capture_http(&mut self)
pub fn capture_http(&mut self)
Sourcepub fn capture_rust(&mut self)
pub fn capture_rust(&mut self)
Sourcepub fn terminate_channel(&mut self)
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();Sourcepub fn add_reporter(&mut self, reporter: impl Reporter + 'static + Send)
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());Sourcepub fn add_boxed_reporter(
&mut self,
reporter: Box<dyn Reporter + Send + 'static>,
)
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);Sourcepub fn add_test(
&mut self,
name: &str,
module: &str,
factory: Arc<dyn Fn() -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>> + Sync + Send + 'static>,
)
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.
Sourcepub fn set_concurrency(&mut self, concurrency: usize)
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 onceSourcepub async fn run(
&mut self,
project_names: &[String],
module_names: &[String],
test_names: &[String],
) -> Result<()>
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
Sourcepub fn list(&self) -> Vec<&TestInfo>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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