private static void assertBitmapsEqual(Bitmap expected, Bitmap actual) {
    if (expected.getHeight() == 0 || expected.getWidth() == 0) {
      throw new AssertionError("bitmap was empty");
    }

    if (expected.getHeight() != actual.getHeight() || expected.getWidth() != actual.getWidth()) {
      throw new AssertionError("bitmap dimensions don't match");
    }

    for (int i = 0; i < expected.getWidth(); i++) {
      for (int j = 0; j < expected.getHeight(); j++) {

        int expectedPixel = expected.getPixel(i, j);
        int actualPixel = actual.getPixel(i, j);

        if (expectedPixel != actualPixel) {
          throw new AssertionError(
              String.format(
                  Locale.US,
                  "Pixels don't match at (%d, %d), Expected %s, got %s",
                  i,
                  j,
                  Long.toHexString(expected.getPixel(i, j)),
                  Long.toHexString(actual.getPixel(i, j))));
        }
      }
    }
  }
Check if the two bitmaps have the same dimensions and pixel data.
core/src/androidTest/java/com/facebook/testing/screenshot/internal/ScreenshotImplTest.java