Skip to content

Android screenshot tests 2#2809

Draft
richardTingle wants to merge 101 commits into
jMonkeyEngine:masterfrom
richardTingle:android-screenshot-tests-2
Draft

Android screenshot tests 2#2809
richardTingle wants to merge 101 commits into
jMonkeyEngine:masterfrom
richardTingle:android-screenshot-tests-2

Conversation

@richardTingle
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a cross-platform screenshot testing framework for jMonkeyEngine, adding dedicated modules for Android, Desktop, and shared test scenarios. It refactors existing tests into reusable scenarios and implements a reporting system using ExtentReports. The reviewer identified several technical issues and improvement opportunities, including a bug in path resolution for image attachments, inaccuracies in the custom timer logic, and performance concerns regarding frequent report serialization and asset manager instantiation. Additionally, it was recommended to use a stable version of Jackson and to replace fragile stack-trace-based test discovery with a more robust mechanism.

Comment thread gradle/libs.versions.toml
report.addTest(testInProgress);
ExtentReportLogCapture.restore();
testInProgress = null;
persistReport(); // it sucks that we do this every test
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Calling persistReport() inside the finished() method of the test watcher causes the entire accumulated report to be serialized to JSON after every test method. This leads to O(N^2) I/O overhead as the number of tests increases. It would be more efficient to persist the report once after all tests in a class or suite have completed.

References
  1. Issues found in test code should be reported with a reduced priority, at most medium.

Comment on lines +81 to +89
try (FileOutputStream fileOutBuf = new FileOutputStream(reportPath().toPath().resolve(fileName).toFile())) {
JmeSystem.writeImageFile(fileOutBuf, "png",originalImage.getData(0),originalImage.getWidth(), originalImage.getHeight());
} catch (IOException e) {
throw new RuntimeException(e);
}
currentTest.addScreenCaptureFromPath(fileName, title);
}

@Override
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The path resolution logic here is incorrect. reportPath() returns the path to the HTML report file (build/reports/ScreenshotDiffReport.html). Calling resolve(fileName) on its Path representation treats the HTML file as a directory, which will cause a FileNotFoundException when attempting to create the FileOutputStream. The images should be saved in the parent directory of the report file.

    @Override
    public void attachImage(String title, String fileName, Image originalImage) {
        try (FileOutputStream fileOutBuf = new FileOutputStream(new File(reportPath().getParentFile(), fileName))) {
            JmeSystem.writeImageFile(fileOutBuf, "png",originalImage.getData(0),originalImage.getWidth(), originalImage.getHeight());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        currentTest.addScreenCaptureFromPath(fileName, title);
    }
References
  1. Issues found in test code should be reported with a reduced priority, at most medium.

private Image readImageFromClasspath(String location) {
AssetManager assetManager = new DesktopAssetManager();
assetManager.registerLocator("", ClasspathLocator.class);
assetManager.registerLoader(StbImageLoader.class, "png", "jpg", "jpeg");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instantiating a new DesktopAssetManager for every image load is resource-intensive. Since reference images are loaded frequently during test execution, consider using a shared AssetManager or a more lightweight image loading mechanism.

References
  1. Issues found in test code should be reported with a reduced priority, at most medium.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 25, 2026

🖼️ Screenshot tests have failed.

The purpose of these tests is to ensure that changes introduced in this PR don't break visual features. They are visual unit tests.

📄 Where to find the report:

⚠️ If you didn't expect to change anything visual:
Fix your changes so the screenshot tests pass.

If you did mean to change things:
Review the replacement images in jme3-screenshot-tests/build/changed-images to make sure they really are improvements and then replace and commit the replacement images at jme3-screenshot-tests/src/test/resources.

If you are creating entirely new tests:
Find the new images in jme3-screenshot-tests/build/changed-images and commit the new images at jme3-screenshot-tests/src/test/resources.

Note; it is very important that the committed reference images are created on the build pipeline, locally created images are not reliable. Similarly tests will fail locally but you can look at the report to check they are "visually similar".

See https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-screenshot-tests/README.md for more information

Contact @richardTingle (aka richtea) for guidance if required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant