auto_test

Crates.ioauto_test
lib.rsauto_test
version0.1.2
created_at2025-11-22 15:09:42.222421+00
updated_at2025-11-24 15:54:45.155999+00
descriptionAutomatically generate test stubs for Rust projects using AST analysis
homepage
repositoryhttps://github.com/m-epasta/auto_test
max_upload_size
id1945418
size144,864
(m-epasta)

documentation

README

AutoTest

Crates.io Documentation License

A Rust library and CLI tool for automatically generating test stubs for Rust projects. Uses AST analysis to understand your code structure and create meaningful integration tests.

Features

  • ๐Ÿ” AST-based Analysis: Analyzes Rust source code using syn and quote
  • ๐Ÿงช Integration Tests: Generates integration tests that call your public API
  • ๐Ÿ“ Modular Organization: Creates separate test files for each module
  • ๐Ÿ› ๏ธ CLI Tool: Command-line interface for easy project integration
  • ๐Ÿ“š Library API: Programmatic access for custom tooling and CI/CD integration
  • ๐Ÿ—๏ธ Type-Aware: Generates appropriate assertions based on return types
  • ๐Ÿงน Clean Architecture: Follows Rust best practices with proper error handling

Installation

As a Cargo binary

cargo install auto_test

As a library dependency

[dependencies]
auto_test = "0.1.1"

Usage

Command Line

Generate tests for your entire Rust project:

auto_test generate /path/to/your/rust/project

Or from within a project directory:

cd /path/to/your/rust/project
auto_test generate .

Configuration

AutoTest supports advanced hierarchical configuration for enterprise workflows. Create an .auto_test.toml or .auto_test.yaml file in your project root:

# Project metadata for GitOps workflows
[project]
name = "my_service"
baseline_branch = "main"

# Generation strategy and behavior
[generation]
strategy = "integration"  # "integration", "unit", or "property"
output_dir = "tests"
skip_functions = ["internal_", "test_"]
timeout_seconds = 120

# Custom assertion patterns
[generation.custom_assertions]
"MyResult" = "assert_matches!(result, MyResult::Ok(_))"
"MyError" = "assert!(result.is_err())"

# Type-safe parameter generation
[types]
constructor_inference = true
builder_detection = true

[types.mappings]
"MyDomainType" = "MyDomainType::builder().build()"
"ComplexType" = "ComplexType::new(\"default\")"

# Performance and execution control
[performance]
parallel = true
parallel_chunk_size = 25
memory_limit_mb = 512
caching_enabled = false

# File discovery and filtering
[filesystem]
respect_gitignore = true
skip_patterns = [
    "**/target/**",
    "**/node_modules/**",
    "**/dist/**"
]

Library API

use auto_test::generate_tests_for_project;

// Generate integration tests for a project
match generate_tests_for_project("./my_project") {
    Ok(()) => println!("Tests generated successfully!"),
    Err(e) => eprintln!("Error: {}", e),
}

Example Output

For a project with this structure:

src/
โ”œโ”€โ”€ lib.rs
โ”œโ”€โ”€ cli/
โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ””โ”€โ”€ generate.rs
โ””โ”€โ”€ core/
    โ”œโ”€โ”€ mod.rs
    โ””โ”€โ”€ analyzer.rs

AutoTest generates:

tests/
โ”œโ”€โ”€ integration_tests.rs
โ”œโ”€โ”€ cli_generate_tests.rs
โ””โ”€โ”€ core_analyzer_rust_analyzer_tests.rs

Each test file contains integration tests that call your public APIs:

#[cfg(test)]
mod tests {
    use auto_test::*;

    #[test]
    fn test_your_function_integration() {
        // Arrange
        // (generated parameter setup)

        // Act
        let result = auto_test::generate_tests_for_project("/tmp/test");

        // Assert
        assert!(result.is_ok());
    }
}

How It Works

  1. Analysis: Parses Rust source code to extract public function signatures
  2. Type Inference: Analyzes parameter types and return values
  3. Test Generation: Creates integration tests with appropriate setup and assertions
  4. Organization: Groups tests by module for maintainability

Supported Types

AutoTest generates test parameters for common Rust types:

  • Primitives: String, &str, i32, u64, bool, and other primitive types
  • Collections: Vec<T>, Option<T>, and other standard library types
  • References: &T, &mut T reference types
  • Custom Types: Falls back to Default::default() for complex structs

Supported Assertions

AutoTest generates appropriate assertions based on return types:

  • Result<T, E> โ†’ Checks for successful operation
  • Option<T> โ†’ Ensures value is present
  • Vec<T> โ†’ Verifies collection is not empty
  • String/&str โ†’ Confirms content is not empty
  • Numbers โ†’ Validates expected value ranges

Limitations

  • Analyzes only public functions by design
  • Currently supports Rust only
  • Complex custom types use default values
  • Generates integration-style tests

License

Licensed under the MIT License. See LICENSE for details.

Changelog

See CHANGELOG.md for a list of changes and version history.

Commit count: 0

cargo fmt