AutoTest
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
synandquote - ๐งช 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
As a library dependency
[]
= "0.1.1"
Usage
Command Line
Generate tests for your entire Rust project:
Or from within a project directory:
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
[]
= "my_service"
= "main"
# Generation strategy and behavior
[]
= "integration" # "integration", "unit", or "property"
= "tests"
= ["internal_", "test_"]
= 120
# Custom assertion patterns
[]
= "assert_matches!(result, MyResult::Ok(_))"
= "assert!(result.is_err())"
# Type-safe parameter generation
[]
= true
= true
[]
= "MyDomainType::builder().build()"
= "ComplexType::new(\"default\")"
# Performance and execution control
[]
= true
= 25
= 512
= false
# File discovery and filtering
[]
= true
= [
"**/target/**",
"**/node_modules/**",
"**/dist/**"
]
Library API
use generate_tests_for_project;
// Generate integration tests for a project
match generate_tests_for_project
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:
How It Works
- Analysis: Parses Rust source code to extract public function signatures
- Type Inference: Analyzes parameter types and return values
- Test Generation: Creates integration tests with appropriate setup and assertions
- 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 Treference 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 operationOption<T>โ Ensures value is presentVec<T>โ Verifies collection is not emptyString/&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.