test

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: BSD-3-Clause Imports: 41 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package test provides utility drivers for running UI tests without rendering to a screen.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTheme

func ApplyTheme(t *testing.T, theme bellui.Theme)

ApplyTheme sets the given theme and waits for it to be applied to the current app. The previous theme is automatically restored when the test completes.

func AssertAllColorNamesDefined

func AssertAllColorNamesDefined(t *testing.T, th bellui.Theme, themeName string)

AssertAllColorNamesDefined asserts that all known color names are defined for the given theme.

func AssertCanvasTappableAt

func AssertCanvasTappableAt(t *testing.T, c core.Canvas, pos geo.Position) bool

AssertCanvasTappableAt asserts that the canvas is tappable at the given position.

func AssertDisabled

func AssertDisabled(t *testing.T, obj core.Disableable) bool

AssertDisabled asserts that a Disableable widget is disabled.

func AssertEnabled

func AssertEnabled(t *testing.T, obj core.Disableable) bool

AssertEnabled asserts that a Disableable widget is enabled.

func AssertFitsWithin

func AssertFitsWithin(t *testing.T, obj core.CanvasObject, maxW, maxH float32) bool

AssertFitsWithin asserts that a widget's size fits within the given bounds. Useful for layout tests without exact size matching.

func AssertHidden

func AssertHidden(t *testing.T, obj core.CanvasObject) bool

AssertHidden asserts that the object is hidden.

func AssertImageMatches

func AssertImageMatches(t *testing.T, masterFilename string, img image.Image, msgAndArgs ...any) bool

AssertImageMatches asserts that the given image is the same as the one stored in the master file. The master filename is relative to the `testdata` directory which is relative to the test. The test `t` fails if the given image is not equal to the loaded master image. In this case the given image is written into a file in `testdata/failed/<masterFilename>` (relative to the test). This path is also reported, thus the file can be used as new master.

func AssertMinSizeAtLeast

func AssertMinSizeAtLeast(t *testing.T, obj core.CanvasObject, minW, minH float32) bool

AssertMinSizeAtLeast asserts that a widget's MinSize is at least the given dimensions. Useful for checking that a widget has reasonable minimum size without exact values.

func AssertNotificationSent

func AssertNotificationSent(t *testing.T, n *bellui.Notification, f func())

AssertNotificationSent allows an app developer to assert that a notification was sent. After the content of f has executed this utility will check that the specified notification was sent.

func AssertObjectRendersToImage

func AssertObjectRendersToImage(t *testing.T, masterFilename string, o core.CanvasObject, msgAndArgs ...any) bool

AssertObjectRendersToImage asserts that the given `CanvasObject` renders the same image as the one stored in the master file. The theme used is the standard test theme which may look different to how it shows on your device. The master filename is relative to the `testdata` directory which is relative to the test. The test `t` fails if the given image is not equal to the loaded master image. In this case the given image is written into a file in `testdata/failed/<masterFilename>` (relative to the test). This path is also reported, thus the file can be used as new master.

Caveat: the canvas is sized to exactly the object's own bounds (MinSize maxed with Size), so anything the object's renderer draws outside those bounds is cropped by the canvas image and will not appear in the comparison. A widget that overflows its bounds therefore renders to a clean, cropped master — looking as if its content were correctly clipped even when it is not. To verify overflow or clipping behaviour, render the object inside a larger canvas (place it in a sized container and use AssertRendersToImage), and use bellui's clipping API (e.g. container.NewClip) to opt a subtree into clipping.

Since: 1.0

func AssertObjectRendersToMarkup

func AssertObjectRendersToMarkup(t *testing.T, masterFilename string, o core.CanvasObject, msgAndArgs ...any) bool

AssertObjectRendersToMarkup asserts that the given `CanvasObject` renders the same markup as the one stored in the master file. The master filename is relative to the `testdata` directory which is relative to the test. The test `t` fails if the rendered markup is not equal to the loaded master markup. In this case the rendered markup is written into a file in `testdata/failed/<masterFilename>` (relative to the test). This path is also reported, thus the file can be used as new master.

Be aware, that the indentation has to use tab characters ('\t') instead of spaces. Every element starts on a new line indented one more than its parent. Closing elements stand on their own line, too, using the same indentation as the opening element. The only exception to this are text elements which do not contain line breaks unless the text includes them.

Caveat: as with AssertObjectRendersToImage, the canvas is sized to exactly the object's own bounds, so markup for content drawn outside those bounds is not captured. Render the object inside a larger canvas (via AssertRendersToMarkup) to observe overflow.

Since: 1.0

func AssertRendersToImage

func AssertRendersToImage(t *testing.T, masterFilename string, c core.Canvas, msgAndArgs ...any) bool

AssertRendersToImage asserts that the given canvas renders the same image as the one stored in the master file. The master filename is relative to the `testdata` directory which is relative to the test. The test `t` fails if the given image is not equal to the loaded master image. In this case the given image is written into a file in `testdata/failed/<masterFilename>` (relative to the test). This path is also reported, thus the file can be used as new master.

Since: 1.0

func AssertRendersToMarkup

func AssertRendersToMarkup(t *testing.T, masterFilename string, c core.Canvas, msgAndArgs ...any) bool

AssertRendersToMarkup asserts that the given canvas renders the same markup as the one stored in the master file. The master filename is relative to the `testdata` directory which is relative to the test. The test `t` fails if the rendered markup is not equal to the loaded master markup. In this case the rendered markup is written into a file in `testdata/failed/<masterFilename>` (relative to the test). This path is also reported, thus the file can be used as new master.

Be aware, that the indentation has to use tab characters ('\t') instead of spaces. Every element starts on a new line indented one more than its parent. Closing elements stand on their own line, too, using the same indentation as the opening element. The only exception to this are text elements which do not contain line breaks unless the text includes them.

Since: 1.0

func AssertVisible

func AssertVisible(t *testing.T, obj core.CanvasObject) bool

AssertVisible asserts that the object is visible.

func AssertWidgetPosition

func AssertWidgetPosition(t *testing.T, obj core.CanvasObject, expectedX, expectedY float32) bool

AssertWidgetPosition asserts that a widget's current position matches expected values.

func AssertWidgetSize

func AssertWidgetSize(t *testing.T, obj core.CanvasObject, expectedW, expectedH float32) bool

AssertWidgetSize asserts that a widget's current size matches the expected size. Uses approximate comparison (within 1 pixel) to handle float rounding.

func Canvas

func Canvas() core.Canvas

Canvas returns a reusable in-memory canvas used for testing

func Compose

func Compose(c core.Canvas, text string, cursorPos int)

Compose sends an in-progress IME composition (preedit) update to the focused object of the canvas when it supports composition (event.Composable). It is a no-op if nothing focusable composable is focused.

Since: 1.0

func ComposeCancel

func ComposeCancel(c core.Canvas)

ComposeCancel cancels any in-progress IME composition on the focused composable object of the canvas. A no-op when the focused object does not support composition.

Since: 1.0

func ComposeCommit

func ComposeCommit(c core.Canvas, text string)

ComposeCommit commits an IME composition on the focused composable object of the canvas, inserting text as if it had been typed. A no-op when the focused object does not support composition.

Since: 1.0

func DoubleTap

func DoubleTap(obj event.DoubleTappable)

DoubleTap simulates a double left mouse click on the specified object.

func Drag

func Drag(c core.Canvas, pos geo.Position, deltaX, deltaY float32)

Drag drags at an absolute position on the canvas. deltaX/Y is the dragging distance: <0 for dragging up/left, >0 for dragging down/right.

The dispatched github.com/belluikit/bellui/event.DragEvent carries an AbsolutePosition of pos, matching the real driver, so widgets that resolve the cursor via AbsolutePosition − driver.AbsolutePositionForObject can be driven headlessly. Drag sends a single Dragged event followed immediately by DragEnd; use DragSteps to observe intermediate drag state.

func DragSteps

func DragSteps(c core.Canvas, pos geo.Position, deltaX, deltaY float32, steps int, onStep func(step int))

DragSteps performs a drag starting at absolute position pos and moving by the given delta, split into the requested number of Dragged events (minimum one), finishing with DragEnd. deltaX/Y is the total dragging distance: <0 for up/left, >0 for down/right.

The draggable is resolved once at pos and receives every event of the gesture (mirroring the real driver, which keeps the drag's origin target for the whole gesture), and each event carries an AbsolutePosition that advances toward the target. If onStep is non-nil it is called after each Dragged event — while the drag is still in progress, before DragEnd — so tests can capture or assert mid-drag state such as ghost previews or drop highlights. onStep receives the 1-based step index.

Since: 1.0

func FocusNext

func FocusNext(c core.Canvas)

FocusNext focuses the next focusable on the canvas.

func FocusPrevious

func FocusPrevious(c core.Canvas)

FocusPrevious focuses the previous focusable on the canvas.

func KnownThemeVariants

func KnownThemeVariants() map[string]bellui.ThemeVariant

KnownThemeVariants returns the known theme variants mapped by a descriptive key.

func LaidOutObjects

func LaidOutObjects(o core.CanvasObject) (objects []core.CanvasObject)

LaidOutObjects returns all core.CanvasObject starting at the given core.CanvasObject which is laid out previously.

func LongPress

func LongPress(obj event.LongPressable)

LongPress simulates a long-press gesture on the specified object.

func LongPressAt

func LongPressAt(obj event.LongPressable, pos geo.Position)

LongPressAt simulates a long-press gesture on the passed object at a specified place within it.

func MoveMouse

func MoveMouse(c core.Canvas, pos geo.Position)

MoveMouse simulates a mouse movement to the given position.

func NewApp

func NewApp() bellui.App

NewApp returns a new dummy app used for testing. It loads a test driver which creates a virtual window in memory for testing.

func NewClipboard

func NewClipboard() bellui.Clipboard

NewClipboard returns a single use in-memory clipboard used for testing

func NewDriver

func NewDriver() bellui.Driver

NewDriver sets up and registers a new dummy driver for test purpose

func NewDriverWithPainter

func NewDriverWithPainter(painter SoftwarePainter) bellui.Driver

NewDriverWithPainter creates a new dummy driver that will pass the given painter to all canvases created

func NewTempApp

func NewTempApp(t testing.TB) bellui.App

NewTempApp returns a new dummy app and tears it down at the end of the test.

Since: 1.0

func NewTempWindow

func NewTempWindow(t testing.TB, content core.CanvasObject) bellui.Window

NewTempWindow creates and registers a new window for test purposes. This window will get removed automatically once the running test ends.

Since: 1.0

func NewTheme

func NewTheme() bellui.Theme

NewTheme returns a new test theme using quiet ugly colors.

func NewWindow

func NewWindow(content core.CanvasObject) bellui.Window

NewWindow creates and registers a new window for test purposes

func RenderObjectToMarkup

func RenderObjectToMarkup(o core.CanvasObject) string

RenderObjectToMarkup renders the given github.com/belluikit/bellui.CanvasObject to a markup string.

Since: 1.0

func RenderToMarkup

func RenderToMarkup(c core.Canvas) string

RenderToMarkup renders the given github.com/belluikit/bellui.Canvas to a markup string.

Since: 1.0

func Scroll

func Scroll(c core.Canvas, pos geo.Position, deltaX, deltaY float32)

Scroll scrolls at an absolute position on the canvas. deltaX/Y is the scrolling distance: <0 for scrolling up/left, >0 for scrolling down/right.

func Tap

func Tap(obj event.Tappable)

Tap simulates a left mouse click on the specified object.

func TapAt

func TapAt(obj event.Tappable, pos geo.Position)

TapAt simulates a left mouse click on the passed object at a specified place within it.

func TapCanvas

func TapCanvas(c core.Canvas, pos geo.Position)

TapCanvas taps at an absolute position on the canvas.

func TapSecondary

func TapSecondary(obj event.SecondaryTappable)

TapSecondary simulates a right mouse click on the specified object.

func TapSecondaryAt

func TapSecondaryAt(obj event.SecondaryTappable, pos geo.Position)

TapSecondaryAt simulates a right mouse click on the passed object at a specified place within it.

func TempWidgetRenderer

func TempWidgetRenderer(t *testing.T, wid core.Widget) core.WidgetRenderer

TempWidgetRenderer allows test scripts to gain access to the current renderer for a widget. This can be used for verifying correctness of rendered components for a widget in unit tests. The widget renderer is automatically destroyed when the test ends.

Since: 1.0

func Theme

func Theme() bellui.Theme

Theme returns a test theme useful for image based tests.

func Type

func Type(obj event.Focusable, chars string)

Type performs a series of key events to simulate typing of a value into the specified object. The focusable object will be focused before typing begins. The chars parameter will be input one rune at a time to the focused object.

func TypeOnCanvas

func TypeOnCanvas(c core.Canvas, chars string)

TypeOnCanvas is like the Type function but it passes the key events to the canvas object rather than a focusable widget.

func WidgetRenderer

func WidgetRenderer(wid core.Widget) core.WidgetRenderer

WidgetRenderer allows test scripts to gain access to the current renderer for a widget. This can be used for verifying correctness of rendered components for a widget in unit tests.

func WithTestTheme

func WithTestTheme(t *testing.T, f func())

WithTestTheme runs a function with the testTheme temporarily set. The original theme is restored immediately after f returns.

Types

type SoftwarePainter

type SoftwarePainter = memcanvas.Painter

SoftwarePainter describes a simple type that can render canvases

type WindowlessCanvas

type WindowlessCanvas = memcanvas.WindowlessCanvas

WindowlessCanvas provides functionality for a canvas to operate without a window

func NewCanvas

func NewCanvas() WindowlessCanvas

NewCanvas returns a single use in-memory canvas used for testing. This canvas has no painter so calls to Capture() will return a blank image.

func NewCanvasWithPainter

func NewCanvasWithPainter(painter SoftwarePainter) WindowlessCanvas

NewCanvasWithPainter allows creation of an in-memory canvas with a specific painter. The painter will be used to render in the Capture() call.

func NewTransparentCanvasWithPainter

func NewTransparentCanvasWithPainter(painter SoftwarePainter) WindowlessCanvas

NewTransparentCanvasWithPainter allows creation of an in-memory canvas with a specific painter without a background color. The painter will be used to render in the Capture() call.

Since: 1.0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL