Skip to content

Testing

The Mythetech.Hermes.Testing package provides comprehensive testing infrastructure for Hermes desktop applications. It includes mock backends, recording capabilities, and fluent assertions for verifying window behavior without requiring a real native window.

Installation

bash
dotnet add package Mythetech.Hermes.Testing

Quick Start

csharp
using Hermes.Testing;
using Hermes.Testing.Assertions;
using Xunit;

public class MyWindowTests
{
    [Fact]
    public void Window_ConfiguresCorrectly()
    {
        using var testWindow = new TestableHermesWindow()
            .SetTitle("My App")
            .SetSize(800, 600);

        testWindow.Show();

        HermesAssert.HasTitle(testWindow.Backend, "My App");
        HermesAssert.HasSize(testWindow.Backend, 800, 600);
    }
}

Key Components

ComponentPurpose
TestableHermesWindowTest-friendly wrapper with fluent configuration
RecordingWindowBackendMock backend that records all interactions
WindowBackendRecordingQuery interface for recorded data
HermesAssertFluent assertion library

What You Can Test

Window Configuration

csharp
using var testWindow = new TestableHermesWindow()
    .SetTitle("Test Window")
    .SetSize(1024, 768)
    .SetPosition(100, 100)
    .SetResizable(true)
    .SetChromeless(false);

testWindow.Show();

HermesAssert.WasShown(testWindow.Backend);

Event Handlers

csharp
var maximizedCalled = false;
using var testWindow = new TestableHermesWindow()
    .OnMaximized(() => maximizedCalled = true);

testWindow.Show();
testWindow.SimulateMaximize();

Assert.True(maximizedCalled);
HermesAssert.WasMaximized(testWindow.Recording);

WebView Communication

csharp
string? receivedMessage = null;
using var testWindow = new TestableHermesWindow()
    .OnWebMessage(msg => receivedMessage = msg);

testWindow.Show();
testWindow.SimulateWebMessage("""{"type":"test","data":"hello"}""");

Assert.Equal("""{"type":"test","data":"hello"}""", receivedMessage);
HermesAssert.ReceivedWebMessageMatching(testWindow.Recording, "hello");

Custom Titlebar Drag Regions

csharp
using var testWindow = new TestableHermesWindow()
    .SetCustomTitleBar(true);

testWindow.Show();
testWindow.SimulateDragRegionClick();

HermesAssert.DetectedDragRegionClick(testWindow.Recording);
csharp
using var testWindow = new TestableHermesWindow()
    .Load("https://example.com");

testWindow.Show();

HermesAssert.NavigatedTo(testWindow.Recording, "https://example.com");

Event Simulation

The testing framework allows you to simulate various window events:

MethodDescription
SimulateWebMessage(message)Simulate receiving a message from JavaScript
SimulateResize(width, height)Simulate window resize
SimulateMove(x, y)Simulate window move
SimulateMaximize()Simulate window maximize
SimulateRestore()Simulate restore from maximized
SimulateFocusIn()Simulate window gaining focus
SimulateFocusOut()Simulate window losing focus
SimulateDragRegionClick()Simulate click on drag region
SimulateDragRegionDoubleClick()Simulate double-click on drag region
SimulateNonDragRegionClick()Simulate click on non-drag region

Topics