Testing
Testing
The test package lets
you test a Bellui UI with ordinary go test. It replaces the real app with an
in-memory one: windows are never shown, nothing needs a GPU or a display, and
tests run on any machine, including CI servers.
A UI test usually does three things:
- Creates a test app and puts the UI in a test window.
- Simulates what a user does: taps, typing, dragging.
- Checks the result, either by reading widget state or by comparing the rendering with a saved golden file.
Test apps and windows, taps, typing, drags, and the assertion helpers.
Compare a widget’s rendering with saved markup or images.
What the test app provides
test.NewApp
creates the app and makes it the current one, so code that calls
bellui.CurrentApp() works. It comes with:
- a test driver whose windows live only in memory;
- in-memory preferences, so tests never touch the user’s real settings;
- app storage rooted in the system’s temporary folder;
- its own clipboard;
- a fixed test theme, so results do not depend on the user’s theme settings.
On the test driver, bellui.Do and bellui.DoAndWait run the function
straight away and return when it has finished. Code that hands work to the UI
thread can be tested without waiting for an event loop.
Prefer test.NewTempApp(t)
and test.NewTempWindow(t, content)
in tests. They do the same as NewApp and NewWindow, and clean up when the
test ends.