Attribute Macro gtk4_macros::test

source ·
Expand description

Attribute macro for declaring GTK tests.

Wraps the standard Rust test attribute with setup logic for GTK. All tests that call into GTK must use this attribute. This attribute can also be used on asynchronous functions; the asynchronous test will be run on the main thread context.

§Technical Details

GTK is a single-threaded library, so Rust’s normal multi-threaded test behavior cannot be used. The #[gtk::test] attribute creates a main thread for GTK and runs all tests on that thread. This has the side effect of making all tests run serially, not in parallel.


use gtk::prelude::*;

fn test_button() {
    let button = gtk::Button::new();