Fork me on GitHub

IMAGE COMPARISON / GET STARTED

Two images.
One clear result.

Bring two BufferedImage values: your approved reference and the new output. Choose Java or the optional Kotlin assertion DSL.

5.0.0Current release ↗

1. Add the test dependency

Declare only the Kotlin adapter. The Java core, Kotlin standard library and required annotations arrive transitively. Java 17 or later is required.

build.gradle.kts · 5.0.0
dependencies {
    testImplementation("dev.nuaforma:image-comparison-kotlin:5.0.0")
}

2. Compare your output

Your JVM test
import dev.nuaforma.image.comparison.kotlin.assertImagesMatch
import java.io.File
import javax.imageio.ImageIO

val expected = requireNotNull(ImageIO.read(File("reference.png")))
val actual = requireNotNull(ImageIO.read(File("actual.png")))

assertImagesMatch(expected, actual, "report preview") {
    pixelTolerance = 0.1
    allowedDifferentPixelsPercent = 0.0
}

A mismatch throws ImageComparisonAssertionError, a framework-independent AssertionError. Its comparisonResult exposes the result and difference image. Save diagnostic files explicitly in your own test code.

3. Make the policy explicit

Tolerance and allowance

pixelTolerance describes how much a pixel's color or alpha may differ. allowedDifferentPixelsPercent describes how many non-excluded pixels may exceed that tolerance. They are different controls. Start with a deliberate policy; do not keep raising either value to hide a regression.

Known variable regions

Use excludeRectangle(x1, y1, x2, y2) for an intentional exclusion. Coordinates are inclusive and must fit inside the reference image. The excluded pixels leave both the numerator and denominator. Different image dimensions always fail the Kotlin assertion.

Version 5.0.0 remains on Maven Central. For future alpha/beta/RC or snapshot versions, follow the public Nexus repository guide for Maven and Gradle; consumer credentials are unnecessary.

The library compares images. Render PDFs or capture screenshots separately, use fixed inputs and review golden images before accepting a new baseline. Bound image dimensions and concurrent work in your own application.