gtk4_macros

Attribute Macro test

Source
#[test]
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.

§Example

use gtk::prelude::*;

#[gtk::test]
fn test_button() {
    let button = gtk::Button::new();
    button.activate();
}