romankh3 / image-comparison

Published on Maven Central Java Library that compares 2 images with the same sizes and shows the differences visually by drawing rectangles. Some parts of the image can be excluded from the comparison. Can be used for automation QA tests.

Home Page:https://t.me/romankh3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[QUESTION] how to tell if the comparison has no difference?

igorgiumellizup opened this issue · comments

Hey Roman Beskrovnyi,
how can I tell if after //After configuring the ImageComparison object, can be executed compare() method: val imageComparisonResult: ImageComparisonResult = imageComparison.compareImages() no difference was found? I only want to generate the result file when there is difference. And also for assertions matter, the code needs to know if there is any difference found. I din't find any info about it in the git hub redame.
Thanks!

Hello, @igorgiumellizup.
Thanks for your interest in image-comparison.
I know, that the README may be better :)
For a better understanding of how image-comparison works, you can see the tests for it.
For example one of them:

@DisplayName("Should perform maximal rectangle count")
    @Test
    public void shouldPerformMaximalRectangleCount() {
        //given
        ImageComparison imageComparison = new ImageComparison("expected.png", "actual.png");
        imageComparison.setMaximalRectangleCount(3);
        BufferedImage expectedImage = readImageFromResources("maximalRectangleCountResult.png");

        //when
        ImageComparisonResult imageComparisonResult = imageComparison.compareImages();

        //then
        assertEquals(MISMATCH, imageComparisonResult.getImageComparisonState());
        assertImagesEqual(expectedImage, imageComparisonResult.getResult());
    }

it's a usual test, which checks ImageComparisonResult.

I hope, it will help you.

Best regards,
Roman B.

What's the API behind 'assertImagesEqual' ?
It would be more efficient not to create the resulting image when there's no difference

assertImagesEqual just a private method in the test class.

It's not created a new result image in the case when they match. Just take one of them.