Crate xray

Source
Expand description

The xray crate provides utilities for performing integration tests on graphical applications, such as games.

For the most basic usage of this libray, you may use one of the utility functions that will perform a screenshot test with the default settings for your library. Currently, the only implemented utility method is gl_screenshot_test which will capture a screenshot using OpenGL of the specified region, and compare it to a reference screenshot loaded from references/<test name>.png.

To customise this behaviour, you should call screenshot_test (returns a Result<(), XrayError>) or assert_screenshot_test (panics on failure) with a custom ScreenshotIo and ScreenshotCaptor.

  1. You may customise the method by which reference images are read, or output images are written by providing a custom ScreenshotIo.
    • For basic customisation of paths, you may create a new instance of FsScreenshotIo and pass it your paths of choice.
    • For more extensive customisation (e.g. using a web service to store screenshots), you may provide a custom implementation of ScreenshotIo.
  2. You may customise the method by which screenshots are taken. This is done by providing a custom implementation of ScreenshotCaptor

Structs§

FsScreenshotIo
Retrieves reference screenshots and stores debugging screenshots using the filesystem. All images are in PNG format.
OpenGlScreenshotCaptor
Captures a screenshot using gl::ReadPixels

Enums§

DynamicImage
A Dynamic Image
IoError
Errors that occur while loading reference images or writing the output images.
ScreenshotError
Errors that occur with the screenshot comparison
XrayError
Reasons that a test could fail.

Traits§

ScreenshotCaptor
Captures a region of the screen for comparison against a reference image.
ScreenshotIo
Load reference images for comparison and store image output in the event of a failed test.

Functions§

assert_screenshot_test
Tests the rendered image against a screenshot and panics if the images do not match or are unable to be taken.
diff_images
Creates an image diff between two images.
gl_screenshot_test
Takes a screenshot using OpenGL and panics if it does not match a reference image.
screenshot_test
Tests the rendered image against the screenshot and returns a Ok(()) if they match, and a Err(ScreenshotError) should the comparison not match or encounter an error.