Expand description
§Tanu - High-performance WebAPI Testing Framework
Tanu is a high-performance, async-friendly, and ergonomic WebAPI testing framework for Rust. It’s designed to be fast, type-safe, and easily extensible with full support for concurrency and async operations.
§Quick Start
You can install tanu
and tokio
by running the following commands in your terminal:
cargo add tanu
cargo add tokio --features full
Write your first test:
use tanu::{check, eyre, http::Client};
#[tanu::test]
async fn get_users() -> eyre::Result<()> {
let client = Client::new();
let response = client
.get("https://api.example.com/users")
.send()
.await?;
check!(response.status().is_success());
Ok(())
}
#[tanu::main]
#[tokio::main]
async fn main() -> eyre::Result<()> {
let runner = run();
let app = tanu::App::new();
app.run(runner).await?;
Ok(())
}
§Key Features
- Async/Await Native: Full support for async operations without boilerplate
- Type-Safe: Leverage Rust’s type system for robust API testing
- Ergonomic Assertions: Use
check!
,check_eq!
, and other assertion macros - Parameterized Testing: Test multiple scenarios with different inputs
- Built-in HTTP Client: No need to set up reqwest or other HTTP clients manually
- Flexible Error Handling: Supports
eyre::Result
,anyhow::Result
, and custom error types - TUI Support: Interactive terminal interface for test execution
- Concurrent Execution: Run tests in parallel for better performance
§Error Types
Tanu supports various Result types for flexible error handling:
eyre::Result<()>
(recommended) - Provides colored backtraces and seamless integrationanyhow::Result<()>
- Compatible with existing anyhow-based codestd::result::Result<(), E>
- Standard Rust Result type with custom error types
§Examples
§Basic HTTP Test
use tanu::{check_eq, eyre, http::Client};
#[tanu::test]
async fn test_api_endpoint() -> eyre::Result<()> {
let client = Client::new();
let response = client
.get("https://httpbin.org/json")
.header("accept", "application/json")
.send()
.await?;
check_eq!(200, response.status().as_u16());
let data: serde_json::Value = response.json().await?;
check!(data.is_object());
Ok(())
}
§Parameterized Tests
use tanu::{check_eq, eyre, http::Client};
#[tanu::test(200)]
#[tanu::test(404)]
#[tanu::test(500)]
async fn test_status_codes(expected_status: u16) -> eyre::Result<()> {
let client = Client::new();
let response = client
.get(&format!("https://httpbin.org/status/{expected_status}"))
.send()
.await?;
check_eq!(expected_status, response.status().as_u16());
Ok(())
}
Re-exports§
pub use anyhow;
pub use eyre;
pub use pretty_assertions;
Modules§
- http
- HTTP Client Module
Macros§
- check
- Asserts that a boolean expression is true.
- check_
eq - Asserts that two expressions are equal using
==
. - check_
ne - Asserts that two expressions are not equal using
!=
. - check_
str_ eq - Asserts that two string expressions are equal with enhanced string diff output.
Structs§
- App
- The main tanu CLI application.
- Config
- tanu’s configuration.
- List
Reporter - A real-time streaming reporter that outputs test results as they happen.
- Null
Reporter - A reporter that produces no output.
- Project
Config - tanu’s project configuration.
- Runner
- The main test execution engine for tanu.
- Table
Reporter - A reporter that displays test results in a summary table after all tests complete.
- Test
Info - Test metadata and identification.
Enums§
- Reporter
Type - Available built-in reporter types.
Traits§
- Reporter
- Trait for implementing custom test result reporting.
Functions§
- get_
config - Get configuration for the current project. This function has to be called in the tokio task created by tanu runner. Otherwise, calling this function will panic.