test

package
v2.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: BSD-3-Clause Imports: 36 Imported by: 24

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 fyne.Theme)

ApplyTheme sets the given theme and waits for it to be applied to the current app.

func AssertAllColorNamesDefined added in v2.5.0

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

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

func AssertCanvasTappableAt

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

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

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 AssertNotificationSent

func AssertNotificationSent(t *testing.T, n *fyne.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 added in v2.3.0

func AssertObjectRendersToImage(t *testing.T, masterFilename string, o fyne.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.

Since 2.3

func AssertObjectRendersToMarkup added in v2.3.0

func AssertObjectRendersToMarkup(t *testing.T, masterFilename string, o fyne.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.

Since 2.3

func AssertRendersToImage added in v2.3.0

func AssertRendersToImage(t *testing.T, masterFilename string, c fyne.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 2.3

func AssertRendersToMarkup

func AssertRendersToMarkup(t *testing.T, masterFilename string, c fyne.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: 2.0

func Canvas

func Canvas() fyne.Canvas

Canvas returns a reusable in-memory canvas used for testing

func DoubleTap

func DoubleTap(obj fyne.DoubleTappable)

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

func Drag

func Drag(c fyne.Canvas, pos fyne.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.

func FocusNext

func FocusNext(c fyne.Canvas)

FocusNext focuses the next focusable on the canvas.

func FocusPrevious

func FocusPrevious(c fyne.Canvas)

FocusPrevious focuses the previous focusable on the canvas.

func KnownThemeVariants added in v2.5.0

func KnownThemeVariants() map[string]fyne.ThemeVariant

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

func LaidOutObjects

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

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

func MoveMouse

func MoveMouse(c fyne.Canvas, pos fyne.Position)

MoveMouse simulates a mouse movement to the given position.

func NewApp

func NewApp() fyne.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() fyne.Clipboard

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

func NewDriver

func NewDriver() fyne.Driver

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

func NewDriverWithPainter

func NewDriverWithPainter(painter SoftwarePainter) fyne.Driver

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

func NewTempApp added in v2.5.0

func NewTempApp(t testing.TB) fyne.App

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

Since: 2.5

func NewTempWindow added in v2.5.0

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

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

Since: 2.5

func NewTheme

func NewTheme() fyne.Theme

NewTheme returns a new test theme using quiet ugly colors.

func NewWindow

func NewWindow(content fyne.CanvasObject) fyne.Window

NewWindow creates and registers a new window for test purposes

func Scroll

func Scroll(c fyne.Canvas, pos fyne.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 fyne.Tappable)

Tap simulates a left mouse click on the specified object.

func TapAt

func TapAt(obj fyne.Tappable, pos fyne.Position)

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

func TapCanvas

func TapCanvas(c fyne.Canvas, pos fyne.Position)

TapCanvas taps at an absolute position on the canvas.

func TapSecondary

func TapSecondary(obj fyne.SecondaryTappable)

TapSecondary simulates a right mouse click on the specified object.

func TapSecondaryAt

func TapSecondaryAt(obj fyne.SecondaryTappable, pos fyne.Position)

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

func TempWidgetRenderer added in v2.5.0

func TempWidgetRenderer(t *testing.T, wid fyne.Widget) fyne.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: 2.5

func Theme

func Theme() fyne.Theme

Theme returns a test theme useful for image based tests.

func Type

func Type(obj fyne.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 fyne.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 fyne.Widget) fyne.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.

Types

type SoftwarePainter

type SoftwarePainter interface {
	Paint(fyne.Canvas) image.Image
}

SoftwarePainter describes a simple type that can render canvases

type WindowlessCanvas

type WindowlessCanvas interface {
	fyne.Canvas

	Padded() bool
	Resize(fyne.Size)
	SetPadded(bool)
	SetScale(float32)
}

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 added in v2.2.0

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: 2.2

Jump to

Keyboard shortcuts

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