Crate xray[][src]

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



Retrieves reference screenshots and stores debugging screenshots using the filesystem. All images are in PNG format.


Captures a screenshot using gl::ReadPixels



A Dynamic Image


Errors that occur while loading reference images or writing the output images.


Errors that occur with the screenshot comparison


Reasons that a test could fail.



Captures a region of the screen for comparison against a reference image.


Load reference images for comparison and store image output in the event of a failed test.



Tests the rendered image against a screenshot and panics if the images do not match or are unable to be taken.


Creates an image diff between two images.


Takes a screenshot using OpenGL and panics if it does not match a reference image.


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.