#[test]Expand description
#[gpui::test] can be used to annotate test functions that run with GPUI support.
It supports both synchronous and asynchronous tests, and can provide you with
as many TestAppContext instances as you need.
The output contains a #[test] annotation so this can be used with any existing
test harness (cargo test or cargo-nextest).
#[gpui::test]
async fn test_foo(mut cx: &TestAppContext) { }In addition to passing a TestAppContext, you can also ask for a StdRnd instance.
this will be seeded with the SEED environment variable and is used internally by
the ForegroundExecutor and BackgroundExecutor to run tasks deterministically in tests.
Using the same StdRng for behavior in your test will allow you to exercise a wide
variety of scenarios and interleavings just by changing the seed.
§Arguments
#[gpui::test]with no arguments runs once with the seed0orSEEDenv var if set.#[gpui::test(seed = 10)]runs once with the seed10.#[gpui::test(seeds(10, 20, 30))]runs three times with seeds10,20, and30.#[gpui::test(iterations = 5)]runs five times, providing as seed the values in the range0..5.#[gpui::test(retries = 3)]runs up to four times if it fails to try and make it pass.#[gpui::test(on_failure = "crate::test::report_failure")]will call the specified function after the tests fail so that you can write out more detail about the failure.
You can combine iterations = ... with seeds(...):
#[gpui::test(iterations = 5, seed = 10)]is equivalent to#[gpui::test(seeds(0, 1, 2, 3, 4, 10))].#[gpui::test(iterations = 5, seeds(10, 20, 30)]is equivalent to#[gpui::test(seeds(0, 1, 2, 3, 4, 10, 20, 30))].#[gpui::test(seeds(10, 20, 30), iterations = 5]is equivalent to#[gpui::test(seeds(0, 1, 2, 3, 4, 10, 20, 30))].
§Environment Variables
SEED: sets a seed for the first runITERATIONS: forces the value of theiterationsargument