# HeadlessUnitTestSession

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-headless/struct-headlessunittestsession/

**struct** · [`ferroui-headless`](/docs/0.5.0/api/ferroui-headless/) · v0.5.0

```rust
struct HeadlessUnitTestSession
```

Headless unit test session that needs to be used by the actual testing
framework. All UI tests are supposed to be executed from one of the
`dispatch` methods to keep execution flow on the UI thread. Disposing
unit test session stops internal dispatcher loop.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Headless/FerroUI.Headless/headless_unit_test_session.rs#L231)

## Members

- [`dispatch`](#function-dispatch)
- [`dispatch_result`](#function-dispatch_result)
- [`dispatch_task`](#function-dispatch_task)
- [`dispose`](#function-dispose)
- [`dispose_async`](#function-dispose_async)
- [`start_new`](#function-start_new)
- [`start_new_with_isolation`](#function-start_new_with_isolation)
- [`get_or_start_for_assembly`](#function-get_or_start_for_assembly)

<a id="function-dispatch"></a>

### dispatch

```rust
fn dispatch(self: &Self, action: impl FnOnce() -> () + Send + 'static, cancellation_token: CancellationToken) -> HeadlessUnitTestTask<()>
```

Queues an action on the dispatcher thread; see
`dispatch_task`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Headless/FerroUI.Headless/headless_unit_test_session.rs#L261)

<a id="function-dispatch_result"></a>

### dispatch_result

```rust
fn dispatch_result<TResult: Send + 'static>(self: &Self, action: impl FnOnce() -> TResult + Send + 'static, cancellation_token: CancellationToken) -> HeadlessUnitTestTask<TResult>
```

Queues an action with a result on the dispatcher thread; see
`dispatch_task`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Headless/FerroUI.Headless/headless_unit_test_session.rs#L277)

<a id="function-dispatch_task"></a>

### dispatch_task

```rust
fn dispatch_task<F, Fut>(self: &Self, action: F, cancellation_token: CancellationToken) -> HeadlessUnitTestTask<<Fut as >::Output>
where F: FnOnce() -> Fut + Send + 'static,
      Fut: Future + 'static,
      <Fut as >::Output: Send + 'static
```

Dispatch method queues an async operation on the dispatcher thread,
creates a new application instance, setting the application services,
and runs `action` parameter.

`action` is the action to execute on the dispatcher thread with the
services; the future it returns never leaves the dispatcher thread.
`cancellation_token` is the cancellation token to cancel execution.
## Panics
If global session was already cancelled and thread killed, it's not
possible to dispatch any actions again (`ObjectDisposedException`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Headless/FerroUI.Headless/headless_unit_test_session.rs#L296)

<a id="function-dispose"></a>

### dispose

```rust
fn dispose(self: &Self)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Headless/FerroUI.Headless/headless_unit_test_session.rs#L410)

<a id="function-dispose_async"></a>

### dispose_async

```rust
async fn dispose_async(self: &Self)
```

The asynchronous form of `dispose`. The dispatch
thread is joined before the future is returned to its first poll:
there is no task to await in its place.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Headless/FerroUI.Headless/headless_unit_test_session.rs#L428)

<a id="function-start_new"></a>

### start_new

```rust
fn start_new(entry_point_type: fn() -> AppBuilder) -> Arc<HeadlessUnitTestSession>
```

Creates instance of `HeadlessUnitTestSession` with the
`FerroTestIsolationLevel::PerTest` isolation.

`entry_point_type` is the parameter from which `AppBuilder` should
be created: the function that builds the application
(`AppBuilder::configure::<TApp>` for an application class).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Headless/FerroUI.Headless/headless_unit_test_session.rs#L438)

<a id="function-start_new_with_isolation"></a>

### start_new_with_isolation

```rust
fn start_new_with_isolation(entry_point_type: fn() -> AppBuilder, isolation_level: FerroTestIsolationLevel) -> Arc<HeadlessUnitTestSession>
```

Creates instance of `HeadlessUnitTestSession`.

`entry_point_type` is the parameter from which `AppBuilder` should
be created. `isolation_level` defines the isolation level for
headless unit tests.
## Panics
Raises the panic of the entry point again.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Headless/FerroUI.Headless/headless_unit_test_session.rs#L450)

<a id="function-get_or_start_for_assembly"></a>

### get_or_start_for_assembly

```rust
fn get_or_start_for_assembly(assembly: Option<&FerroTestAssembly>) -> Arc<HeadlessUnitTestSession>
```

Creates a session from the test application attribute of the
assembly or reuses any existing. If the attribute doesn't exist,
empty application is used.

`None` is the assembly of the session itself.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Headless/FerroUI.Headless/headless_unit_test_session.rs#L528)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- [`IDisposable`](/docs/0.5.0/api/ferroui-base/reactive/use-idisposable/)
- `ErasedDestructor`
- `IntoEither`

## Availability

Extracted for `x86_64-unknown-linux-gnu`, `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
