slint-ui/slint · error
the testing backend must be initialized first
Error message
the testing backend must be initialized first
What it means
set_system_accent_color can only forward the accent color through the testing backend's platform, and that platform exists only after one of the init functions ran. This panic fires when the test calls set_system_accent_color before initializing the testing backend (or after it was replaced), i.e. an ordering bug in the test setup rather than a data problem.
Solutions
- Call i_slint_backend_testing::init() or init_no_event_loop() (or init_integration_test_with_mock_time) before set_system_accent_color
- Ensure no other platform backend was initialized first; slint::platform::set_platform only succeeds once per process
- In tests, initialize the testing backend in a setup/before-each hook and keep a single initialization per process
Defensive patterns
Strategy: validation
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@bb937076de (2026-09-16).
Data as JSON: /api/errors/a4469e56438c3f8f.
Report an issue: GitHub.
Appendix: 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};
// Listed explicitly, in the order they take in the fallback chain: NotoSans-Regular is
// the default upright face and comes first. Embedding the whole directory instead would
// make the chain depend on filesystem iteration order, and would pull in whatever else
// lives there - the `.license` files, `convert.sh`, and the gitignored upstream fonts
// that script downloads into a subdirectory.
static FONTS: &[&[u8]] = &[
include_bytes!("../../../tests/screenshots/fonts/NotoSans-Regular.ttf"),View on GitHub (pinned to bb937076de)