ferroui_headless/headless_unit_test_isolation_attribute.rs
1//! Port of `HeadlessUnitTestIsolationAttribute.cs`: the isolation level of
2//! headless unit tests and the attribute that states it.
3//!
4//! The attribute of the original is an assembly attribute. There are no
5//! assembly attributes: the value is a field of the
6//! [`FerroTestAssembly`](crate::FerroTestAssembly) that a test crate hands
7//! to
8//! [`HeadlessUnitTestSession::get_or_start_for_assembly`](crate::HeadlessUnitTestSession::get_or_start_for_assembly).
9
10/// Defines the isolation level for headless unit tests, controlling how the
11/// application and its associated dispatcher are managed between test runs.
12#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
13pub enum FerroTestIsolationLevel {
14 /// Reuses a single application and dispatcher instance across all tests
15 /// within the assembly.
16 ///
17 /// Tests must not rely on any global or persistent state that could
18 /// leak between runs. Headless framework won't dispose any resources
19 /// after tests when using this mode.
20 PerAssembly,
21
22 /// Recreates the application and dispatcher for each individual test
23 /// method.
24 ///
25 /// This mode ensures complete test isolation, and should be used for
26 /// tests that modify global application state or rely on a clean
27 /// dispatcher environment. This is the default isolation level if none
28 /// is specified.
29 PerTest,
30}
31
32/// Specifies how headless unit tests should be isolated from each other,
33/// defining when the test runtime should recreate the application and
34/// dispatcher instances.
35#[derive(Clone, Copy, Debug, PartialEq, Eq)]
36pub struct FerroTestIsolationAttribute {
37 isolation_level: FerroTestIsolationLevel,
38}
39
40impl FerroTestIsolationAttribute {
41 pub const fn new(isolation_level: FerroTestIsolationLevel) -> Self {
42 Self { isolation_level }
43 }
44
45 /// Gets the isolation level for headless tests.
46 pub fn isolation_level(&self) -> FerroTestIsolationLevel {
47 self.isolation_level
48 }
49}