Files
TinyTorch/docs/testing_pattern.md
Vijay Janapa Reddi 5264b6aa68 Move testing utilities to tito/tools for better software architecture
- Move testing utilities from tinytorch/utils/testing.py to tito/tools/testing.py
- Update all module imports to use tito.tools.testing
- Remove testing utilities from core TinyTorch package
- Testing utilities are development tools, not part of the ML library
- Maintains clean separation between library code and development toolchain
- All tests continue to work correctly with improved architecture
2025-07-13 21:05:11 -04:00

2.6 KiB

TinyTorch Standardized Testing Pattern

Overview

All TinyTorch modules use a consistent testing pattern that ensures:

  • Consistent output format across all modules
  • No code duplication - shared utilities handle formatting
  • Easy test registration - just register functions and run
  • Comprehensive reporting - detailed pass/fail breakdown

Usage Pattern

1. Import the Testing Utilities

import sys
import os

# Add utils to path
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'utils'))
from testing import create_test_runner

2. Write Your Test Functions

def test_feature_a():
    """Test feature A functionality."""
    # Your test code here
    assert something_works(), "Feature A should work"
    print("✅ Feature A tests passed!")

def test_feature_b():
    """Test feature B functionality."""
    # Your test code here
    assert something_else_works(), "Feature B should work"
    print("✅ Feature B tests passed!")

3. Register and Run Tests

if __name__ == "__main__":
    # Create test runner for this module
    test_runner = create_test_runner("YourModule")
    
    # Register all tests
    test_runner.register_test("Feature A", test_feature_a)
    test_runner.register_test("Feature B", test_feature_b)
    
    # Run all tests with consistent output
    success = test_runner.run_all_tests()

Standard Output Format

Every module will produce identical output:

🔬 Running YourModule Module Tests...
==================================================
🧪 Testing Feature A... ✅ PASSED
🧪 Testing Feature B... ✅ PASSED

============================================================
🎯 YOURMODULE MODULE TESTING COMPLETE
============================================================
🎉 CONGRATULATIONS! All tests passed!

✅ YourModule Module Status: 2/2 tests passed (100%)

📊 Detailed Results:
   Feature A: ✅ PASSED
   Feature B: ✅ PASSED

📈 Progress: YourModule Module ✓ COMPLETE

🚀 Ready for the next module!

Benefits

  1. Consistency: All modules have identical testing output
  2. No Duplication: Testing utilities are shared across modules
  3. Easy Maintenance: Changes to format only need to be made in one place
  4. Scalable: Works for any number of tests and modules
  5. Professional: Clean, standardized output suitable for educational use

Implementation

  • Shared utilities: modules/source/utils/testing.py
  • Test registration: Each module registers its tests
  • Consistent format: All modules get identical summary output
  • Error handling: Detailed error reporting for failed tests