slint-ui/slint · error
the testing backend must be initialized first
Error message
the testing backend must be initialized first
What it means
Error "the testing backend must be initialized first" thrown in slint-ui/slint.
Source
Thrown at internal/backends/testing/lib.rs:94
threading: true,
..Default::default()
},
)))
.expect("platform already initialized");
}
/// Advance the simulated mock time by the specified duration. Use in combination with
/// [`init_integration_test_with_mock_time()`] or [`init_no_event_loop()`].
#[cfg(not(feature = "internal"))]
pub fn mock_elapsed_time(duration: std::time::Duration) {
testing_backend::mock_elapsed_time(duration.as_millis() as _);
}
/// Set the system accent color, as a platform backend would when the OS theme changes.
/// Must be called after initializing the testing backend (e.g. after [`init_no_event_loop()`]).
pub fn set_system_accent_color(color: i_slint_core::Color) {
i_slint_core::context::with_global_context(
|| panic!("the testing backend must be initialized first"),
|ctx| ctx.set_accent_color(color),
)
.unwrap();
}
/// Replace the font collection with embedded NotoSans fonts for deterministic test results.
/// Must be called after initializing the testing backend (e.g. after [`init_no_event_loop()`]).
#[cfg(feature = "internal")]
pub fn configure_test_fonts() {
use i_slint_common::sharedfontique::{FALLBACK_FAMILIES, fontique};
use include_dir::{Dir, include_dir};
static FONTS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/../../../tests/screenshots/fonts");
// Pin the primary by name so its position in the fallback chain doesn't depend on
// filesystem iteration order. NotoSans-Regular wins as the default upright face.
const PRIMARY: &str = "NotoSans-Regular.ttf";
i_slint_core::with_global_context(View on GitHub (pinned to 3fd8f2ec03)
Solutions
- Call i_slint_backend_testing::init() before using testing backend functions.
- Ensure the test binary links the testing backend and initializes it at startup.
When it happens
Trigger: Thrown at internal/backends/testing/lib.rs:94 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of slint-ui/slint@3fd8f2ec03 (2026-08-19).
Data as JSON: /api/errors/a4469e56438c3f8f.
Report an issue: GitHub.