Skip to main content
Version: 11.0.x

Manual Setup of Headless Platform


This page explains an advanced usage scenario with the Headless platform. We recommend using the XUnit or NUnit testing frameworks instead.

Install Packages

To set up the Headless platform, you need to install two packages:


The Headless platform doesn't require any specific theme, and it is possible to swap FluentTheme with any other.

Setup Application

As in any other Avalonia app, an Application instance needs to be created, and themes need to be applied. When using the Headless platform, the setup is not much different from a regular Avalonia app and can mostly be reused.

<Application xmlns=""
<FluentTheme />

And the code:

using Avalonia;
using Avalonia.Headless;

public class App : Application
public override void Initialize()

Run Headless Session

using Avalonia.Controls;
using Avalonia.Headless;

// Start Headless session passing Application type.
using var session = HeadlessUnitTestSession.StartNew(typeof(App));

// Since the Headless session has its own thread internally, we need to dispatch actions there:
await session.Dispatch(() =>
// Setup controls:
var textBox = new TextBox();
var window = new Window { Content = textBox };

// Open window:

// Focus text box:

// Simulate text input:
window.KeyTextInput("Hello World");

// Assert:
if (textBox.Text != "Hello World")
throw new Exception("Assert");
}, CancellationToken.None);