XRay
Screenshot testing for Rust games
Features
- Compares screenshots taken at test time with reference screenshots.
- Outputs the actual screenshot taken and a image containing only those pixels which differ.
- Compatible with OpenGL apps
Example test (for a Piston + OpenGL app):
```rust
[test]
fn checkbasicscreen() {
let size = [1280, 720];
let mut app = App::new(size, buildglutinwindow(size));
let Size { width: drawwidth, height: drawheight } = app.window.drawsize();
let Size { width, height } = app.window.size();
app.renderintoviewport(Viewport {
rect: [0, 0, drawwidth as i32, drawheight as i32],
windowsize: [width, height],
drawsize: [drawwidth, drawheight]
});
xray::screenshottest("basicrendering/initialmap", 0, 0, drawwidth, drawheight);
}
```
Usage
- Write your test.
- Run your test.
- The first time the test will fail, as there is no reference screenshot. The actual screenshot taken
during the test will be stored at
test_output/<test_name>/actual.png
.
- Verify the generated screenshot is correct.
- Copy the generated screenshot to
references/<test_name>.png
- Continue development.
Known Issues
- Linux/X11: You should run the tests in single threaded mode. Since each test will be creating X11
windows to render into, and creating multiple windows too quickly will result in some of them
failing to obtain an input method. This may be possible to fix by wrapping the new window creation in
a mutex, but I have't had time to investigate.