tinytorch/site/tito/testing.md
Purpose: Complete guide to TinyTorch's testing infrastructure. Understand the test hierarchy, run specific test types, and validate releases.
TinyTorch uses a progressive testing hierarchy that mirrors how the framework builds from simple components to full functionality:
flowchart TB
subgraph hierarchy["Test Hierarchy (Bottom to Top)"]
direction TB
INLINE["๐งช <b>INLINE TESTS</b>
Embedded nbgrader tests in src/ files
<i>Progressive build validation</i>"]
UNIT["๐ฌ <b>UNIT TESTS</b>
Individual component tests
<i>pytest in tests/</i>"]
CLI["โจ๏ธ <b>CLI TESTS</b>
Command-line interface validation
<i>TITO command testing</i>"]
INTEGRATION["๐ <b>INTEGRATION TESTS</b>
Cross-module interactions
<i>Module 2 depends on Module 1</i>"]
E2E["๐ <b>END-TO-END TESTS</b>
Complete user journeys
<i>setup โ module โ milestone</i>"]
MILESTONE["๐ <b>MILESTONE TESTS</b>
Historical ML recreations
<i>Require full TinyTorch package</i>"]
RELEASE["โ ๏ธ <b>RELEASE VALIDATION</b>
Full curriculum rebuild + all tests
<i>DESTRUCTIVE - releases only</i>"]
INLINE --> UNIT
UNIT --> CLI
CLI --> INTEGRATION
INTEGRATION --> E2E
E2E --> MILESTONE
MILESTONE --> RELEASE
end
style INLINE fill:#e8f5e9,stroke:#4caf50,stroke-width:2px
style UNIT fill:#e3f2fd,stroke:#2196f3,stroke-width:2px
style CLI fill:#e3f2fd,stroke:#2196f3,stroke-width:2px
style INTEGRATION fill:#fff3e0,stroke:#ff9800,stroke-width:2px
style E2E fill:#fff3e0,stroke:#ff9800,stroke-width:2px
style MILESTONE fill:#fce4ec,stroke:#e91e63,stroke-width:2px
style RELEASE fill:#ffebee,stroke:#f44336,stroke-width:3px
| Flag | What It Tests | When to Use |
|---|---|---|
--inline | Embedded tests in src/*.py | After editing module source code |
--unit | Pytest unit tests | Quick validation during development |
--cli | CLI command tests | After modifying TITO commands |
--integration | Cross-module tests | After changes affecting multiple modules |
--e2e | End-to-end journeys | Before merging major features |
--milestone | Historical ML tests | After full package changes |
--all | Everything except release | Before pushing to dev branch |
--release | Full destructive validation | Before releases only |
tito dev test CommandAll testing is unified under a single command with specific flags:
# Default: runs unit tests only
tito dev test
# Run specific test types
tito dev test --inline # Module source tests (progressive)
tito dev test --unit # Pytest unit tests
tito dev test --cli # CLI tests
tito dev test --integration # Integration tests
tito dev test --e2e # End-to-end tests
tito dev test --milestone # Milestone tests
# Run all tests (except release)
tito dev test --all
# Full release validation (DESTRUCTIVE)
tito dev test --release
You can combine multiple flags:
# Run unit and CLI tests
tito dev test --unit --cli
# Run inline and integration tests
tito dev test --inline --integration
Test a specific module with the --module flag (or -m shorthand):
# Run inline tests for module 06 only
tito dev test --inline --module 06
# Run unit tests for module 03
tito dev test --unit --module 03
# Shorthand works too
tito dev test --inline -m 06
For automation, use --ci for JSON output:
tito dev test --all --ci
--inline)What: Embedded tests inside src/XX_module/XX_module.py files using nbgrader format.
Why: These are the student-facing tests that validate each module's implementation before export.
How It Works:
tito module complete for each module progressivelyExample inline test in source:
# %% nbgrader={"grade": true, "grade_id": "tensor_creation", "points": 5}
# Test tensor creation
t = Tensor([1, 2, 3])
assert t.shape == (3,), "Shape should be (3,)"
assert t.data[0] == 1, "First element should be 1"
When to run: After editing any src/ file to ensure student tests still pass.
--unit)What: Pytest tests in tests/01_tensor/, tests/02_activations/, etc.
Why: Additional validation beyond inline tests. May test edge cases, error handling, or implementation details not covered in student exercises.
Location: tinytorch/tests/ directory structure mirrors module structure.
When to run: Default test type. Run frequently during development.
--cli)What: Tests for the TITO command-line interface.
Why: Ensures all CLI commands work correctly, help text is consistent, and user-facing behavior is stable.
Location: tinytorch/tests/cli/
When to run: After modifying any command in tito/commands/.
--integration)What: Tests that verify cross-module functionality.
Why: Module 2 depends on Module 1. Integration tests ensure the dependencies work correctly together.
Location: tinytorch/tests/integration/
Example: Testing that Tensor from Module 1 works correctly with Linear from Module 5.
When to run: After changes that might affect module interactions.
--e2e)What: Complete user journey tests.
Why: Validates the entire workflow a student or developer would follow.
Location: tinytorch/tests/e2e/
Example journeys tested:
When to run: Before merging significant features.
--milestone)What: Tests that validate the historical ML milestone scripts.
Why: Milestones are key student checkpoints. They MUST work reliably.
Location: tinytorch/tests/milestones/
Milestones tested:
Requirements: All modules must be exported to tinytorch/core/ before milestone tests can run.
When to run: After any changes to core TinyTorch functionality.
--all)What: Runs inline, unit, cli, integration, e2e, and milestone tests.
Why: Comprehensive validation without the destructive reset of release validation.
When to run: Before pushing to the dev branch or creating PRs.
--release)What: Full curriculum rebuild and validation.
Why: Ensures a fresh installation would work correctly.
โ ๏ธ WARNING: This is DESTRUCTIVE. It will:
tinytorch/core/ directoryWhen to run: Only before releases. Never run casually.
The GitHub Actions workflow supports all test types:
# .github/workflows/tinytorch-validate-dev.yml
# Quick tests on every push
- name: Run Quick Tests
run: tito dev test --unit --cli
# Full tests on PR to dev
- name: Run Full Tests
run: tito dev test --all
# Release validation (manual trigger only)
- name: Release Validation
run: tito dev test --release
tinytorch/
โโโ tests/
โ โโโ 01_tensor/ # Unit tests for Module 01
โ โโโ 02_activations/ # Unit tests for Module 02
โ โโโ ...
โ โโโ cli/ # CLI command tests
โ โ โโโ test_cli_execution.py
โ โ โโโ test_cli_help_consistency.py
โ โ โโโ test_cli_registry.py
โ โโโ integration/ # Cross-module tests
โ โโโ e2e/ # End-to-end journey tests
โ โ โโโ test_user_journey.py
โ โโโ milestones/ # Milestone script tests
โ โโโ test_milestones_run.py
โโโ src/
โโโ 01_tensor/
โ โโโ 01_tensor.py # Contains inline tests
โโโ 02_activations/
โ โโโ 02_activations.py
โโโ ...
# Quick validation while coding
tito dev test --unit
# After editing a module
tito dev test --inline --module 06
# Before committing
tito dev test --unit --cli
# After implementing a feature
tito dev test --unit --integration
# Before creating PR
tito dev test --all
# Full validation (in clean environment)
tito dev test --release
Cause: The module hasn't been exported yet.
Solution: Run tito module complete XX or tito dev export XX first.
Cause: Not all required modules are exported.
Solution: Run tito dev test --inline first to progressively build all modules.
Cause: CI starts fresh without exported modules.
Solution: Ensure CI workflow runs module export before tests.
A well-tested framework is a trusted framework. Use this testing hierarchy to ensure TinyTorch remains reliable for students worldwide.