Testing a Leaf-Counting System
BehavioralModel answerLast updated
Design a comprehensive test strategy for a system that counts leaves on a large tree, addressing ambiguity, test oracles, functional coverage, and scale.
You're designing a test plan for a system that counts leaves on a large tree.
This prompt is intentionally vague. Your task includes determining what the system actually does before creating tests for it.
Consider these angles:
- What type of system is this? A computer vision application analyzing photos of real trees, or software that traverses a tree data structure?
- What level of precision is required? Must the count be exact, or is approximation within some margin acceptable?
- What does "large" mean in this context? Are there constraints on processing time or memory usage?
- What form do inputs and outputs take? Images, node streams, a single integer, detailed breakdowns?
Provide a structured test strategy that demonstrates how you'd validate this system's correctness and reliability.
Hints
Hint 1
Start by asking questions to narrow down what you're actually testing—the system type determines everything else about your strategy.
Hint 2
Think about how you'll establish correct answers (your test oracle) for different scenarios—this varies significantly between physical and logical trees.
Hint 3
Consider the full spectrum: happy paths, edge cases, error conditions, performance under load, and what quality bar must be met before release.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Approach
A strong test strategy starts with disambiguation, then builds layered coverage across functional correctness, boundaries, scale, and quality gates.
1. Clarify the System
Before writing any tests, establish what you're testing:
System type:
- Physical tree analysis (computer vision on images/scans)?
- Data structure traversal (counting leaf nodes in a software tree)?
Accuracy requirements:
- Exact count needed, or is ±5% acceptable?
- Does the application domain dictate precision (scientific vs. estimate)?
Scale parameters:
- How many leaves constitute "large"? Thousands? Millions?
- Are there latency requirements (real-time vs. batch)?
- Memory constraints on the execution environment?
Input/output format:
- Images, point clouds, serialized data structures?
- Single integer output, or richer metadata (per-branch counts, confidence scores)?
Assume for this answer we're testing a computer vision system that analyzes tree photos and returns leaf counts within ±10% accuracy.
2. Establish Test Oracles
You need ground truth to validate outputs:
Manual counting: For small test trees, have humans count leaves in controlled photos. Use these as baseline datasets.
Synthetic data: Generate 3D tree models with known leaf counts, render from various angles. Perfect ground truth, full control over parameters.
Cross-validation: Run multiple independent counting methods (different algorithms, human annotators) and flag disagreements for review.
Statistical sampling: For very large trees, manually count representative samples and extrapolate to validate system estimates fall within expected confidence intervals.
3. Functional Test Cases
Happy path:
- Standard deciduous tree, good lighting, clear leaf visibility
- Standard conifer, dense needle clusters
- Expected output within tolerance of ground truth
Boundary conditions:
- Minimum size: single leaf (count = 1)
- Empty tree (winter, no leaves): count = 0
- Very dense foliage where leaves overlap heavily
- Sparse tree with widely separated leaves
Edge cases:
- Partially obscured tree (behind fence, other objects)
- Unusual lighting: shadows, backlit, dappled sunlight
- Seasonal transition: some leaves brown/falling
- Mixed species in frame—does it count all or target a specific tree?
Negative cases:
- No tree in image—how does system respond?
- Non-tree objects (bushes, potted plants)
- Corrupted or malformed input data
- Extremely low resolution images
4. Non-Functional Testing
Performance:
- Measure latency for images at different resolutions
- Test throughput: can it process a batch of 1000 images in reasonable time?
- Memory profiling: does it leak or spike beyond available resources?
Scale:
- Progressively larger trees: 100 leaves, 1K, 10K, 100K
- Does accuracy degrade or processing time become prohibitive?
Robustness:
- Run same image multiple times—is output consistent?
- Slightly modified inputs (cropped, rotated, compressed)—do results stay stable?
- Stress test: many concurrent requests, sustained load
Failure modes:
- Network interruptions (if cloud-based processing)
- Partial input corruption—graceful degradation vs. crash?
- What error messages or logging exist for debugging?
5. Test Organization
Unit tests: Individual components (image preprocessing, feature detection, counting algorithm) with mocked dependencies.
Integration tests: Full pipeline from image input to count output, using test fixtures with known answers.
End-to-end tests: Simulate production usage patterns, including API calls, async processing, result retrieval.
Regression suite: Automated tests that run on every code change to catch breakage. Include past bug scenarios to prevent reoccurrence.
6. Release Criteria
Define what "good enough to ship" means:
- Accuracy: 90% of test cases within ±10% of ground truth
- No crashes or hangs on any valid input
- Latency: 95th percentile under 5 seconds for typical images
- Graceful handling of all error conditions with actionable messages
- Documentation of known limitations (e.g., "not reliable for trees smaller than X pixels")
Common Mistakes
- Skipping clarification: Diving into tests without understanding the system leads to irrelevant test cases.
- No oracle strategy: Testing without ground truth means you can't validate correctness.
- Only happy paths: Missing boundary and error cases leaves gaps in coverage.
- Ignoring non-functional aspects: A functionally correct but unusably slow system fails in production.
- Manual-only testing: Without automation, regression testing becomes impractical as the system evolves.
A comprehensive strategy addresses all these dimensions, balancing thoroughness with resource constraints to deliver confidence in system quality.