Added Snapshot-Based Testing to NumberInput Widget
Added Snapshot-Based Testing to NumberInput Widget
#397 in iced-rs/iced_aw — merged 2026-01-01
Summary of Changes
Enhanced the number_input_displays_correct_initial_value test to include visual regression testing using iced_test simulator's snapshot capabilities.
Changes Made
Modified:
tests/number_input_integration_tests.rs- Added snapshot validation to existing test (lines 75-88)number_input_displays_correct_initial_value
Output:
tests/snapshots/number_input_initial_value_100-wgpu.png- Visual baseline (18KB)tests/snapshots/number_input_initial_value_100-wgpu.sha256- Hash baseline (64 bytes)
What This Enables
The test now performs three levels of validation:
- Text validation - Verifies "100" is displayed (existing)
- Hash validation - Fast SHA-256 comparison for regression detection (new)
- Image validation - Pixel-perfect visual comparison against baseline PNG (new)
Testing Approach
Using iced_test::Simulator snapshot API:
let snapshot = ui.snapshot(&iced::Theme::Light)?;
assert!(snapshot.matches_hash("tests/snapshots/number_input_initial_value_100")?);
assert!(snapshot.matches_image("tests/snapshots/number_input_initial_value_100")?);
(On first run, baseline files are auto-generated. Subsequent runs compare against these baselines.)
How to Test
cargo test number_input_displays_correct_initial_value --test number_input_integration_tests
(Test should pass, validating against committed baselines.)
Questions for Review
- Should we adopt this pattern for other widget tests?
- The baseline files are committed to enable CI regression detection - is this acceptable for repo size?
- Should we document this pattern in tests/README.md?
References
Last updated 2026-05-14
Links to this note
Credits
Merged pull requests, newest first.