Expand description
Headless runner for testing Masonry applications.
The primary type from this crate is TestHarness, which creates a host for any Widget.
The widget can of course have children, which allows this crate to be used for testing entire applications.
The testing harness can:
- Simulate any external event which Masonry handles, including mouse movement, key presses, text input, accessibility events.
- Control the flow of time to the application (i.e. for testing animations).
- Take screenshots of the application, save these to a file, and ensure that these are up-to-date. See Screenshots for more details.
Testing in Masonry is also documented in the Testing widgets in Masonry chapter in Masonry’s book.
This crate can be accessed for applications using Masonry as masonry::testing, if Masonry’s testing feature is enabled.
For applications which are using only Masonry Core, you should depend on masonry_testing directly.
§Screenshots
Tests using TestHarness can include snapshot steps by using the assert_render_snapshot screenshot.
This renders the application being tested, then compares it against the png file with the given name
from the screenshots folder (in the package being tested, i.e. adjacent to its Cargo.toml file).
Masonry Testing will update the reference file when the MASONRY_TEST_BLESS environment variable has a value of 1.
This can be used if the file doesn’t exist, or there’s an expected difference.
The screenshots are losslessly compressed (using oxipng) and limited to a small maximum file size (this
limit has an escape hatch).
This ensures that the screenshots are small enough to embed in a git repository with limited risk
of clone times growing unreasonably.
UI screenshots compress well, so we expect this to be scalable.
For repositories hosted on GitHub, this scheme also allows for including screenshots of your app or widgets in hosted documentation, although we haven’t documented this publicly yet.
§Examples
For examples of this crate in use
- To test applications: see the tests in Masonry’s examples.
- To test widgets: see the
testsmodule in each widget in Masonry.
Macros§
- assert_
debug_ panics - Checks that the given expression panics in debug mode. No-op in release mode.
- assert_
failing_ render_ snapshot - Assert a snapshot of a rendered frame of your app, expecting it to fail.
- assert_
render_ snapshot - Assert a snapshot of a rendered frame of your app.
Structs§
- Debug
Name - Helper property for tying a name to a widget.
- Modular
Widget - A widget that can be constructed from individual functions, builder-style.
- Recorder
- A wrapper widget that records each time one of its methods is called.
- Recording
- A recording of widget method calls.
- Test
Harness - A safe headless environment to test widgets in.
- Test
Harness Params - Parameters for creating a
TestHarness. - Wrapper
Widget - A basic wrapper widget that can replace its child.
Enums§
- Record
- A recording of a method call on a widget.
Constants§
- PRIMARY_
MOUSE - A
PointerInfofor a primary mouse, for testing.
Traits§
- Test
Widget Ext - External trait implemented for all widgets.
Functions§
- assert_
all - Assert that
predreturns true for every item initer. - assert_
any - Assert that
predreturns true for at least one item initer. - assert_
none - Assert that
predreturns false for every item initer. - widget_
ids - Convenience function to return an array of unique widget ids.