docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class ImageAssert

    Provides test assertion helpers for working with images.

    Inheritance
    object
    ImageAssert
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.TestTools.Graphics
    Assembly: UnityEngine.TestTools.Graphics.dll
    Syntax
    public class ImageAssert

    Methods

    AllocatesMemory(Camera, ImageComparisonSettings, int)

    Render an image from the given camera and check if it allocated memory while doing so.

    Declaration
    public static void AllocatesMemory(Camera camera, ImageComparisonSettings settings = null, int gcAllocThreshold = 0)
    Parameters
    Type Name Description
    Camera camera

    The camera to render from.

    ImageComparisonSettings settings

    The image comparison settings for this comparison.

    int gcAllocThreshold

    The threshold for the number of GC allocations.

    AreEqual(Texture2D, IEnumerable<Camera>, ImageComparisonSettings, string, bool)

    Render an image from the given cameras and compare it to the reference image.

    Declaration
    public static void AreEqual(Texture2D expected, IEnumerable<Camera> cameras, ImageComparisonSettings settings = null, string expectedImagePathLog = null, bool saveFailedImageToDisk = false)
    Parameters
    Type Name Description
    Texture2D expected

    The expected image to compare against.

    IEnumerable<Camera> cameras

    The cameras to render from. All cameras will be rendered to the same rendered texture. This useful when testing camera stacking/overlay.

    ImageComparisonSettings settings

    Optional settings that control how the image comparison is performed. Can be null, in which case the rendered image is required to be exactly identical to the reference.

    string expectedImagePathLog

    The log message to display if the test fails.

    bool saveFailedImageToDisk

    If true, the actual image will be saved to disk if the test fails.

    AreEqual(Texture2D, Camera, ImageComparisonSettings, string, bool)

    Render an image from the given camera and compare it to the reference image.

    Declaration
    public static void AreEqual(Texture2D expected, Camera camera, ImageComparisonSettings settings = null, string expectedImagePathLog = null, bool saveFailedImageToDisk = false)
    Parameters
    Type Name Description
    Texture2D expected

    The expected image to compare against.

    Camera camera

    The camera to render from.

    ImageComparisonSettings settings

    Optional settings that control how the image comparison is performed. Can be null, in which case the rendered image is required to be exactly identical to the reference.

    string expectedImagePathLog

    The log message to display if the test fails.

    bool saveFailedImageToDisk

    If true, the actual image will be saved to disk if the test fails.

    AreEqual(Texture2D, Texture2D, ImageComparisonSettings, string, bool, bool, bool)

    Compares an image to a 'reference' image to see if it looks correct.

    Declaration
    public static void AreEqual(Texture2D expected, Texture2D actual, ImageComparisonSettings settings = null, string expectedImagePathLog = null, bool saveFailedImage = true, bool saveFailedImageToDisk = false, bool logMessages = true)
    Parameters
    Type Name Description
    Texture2D expected

    What the image is supposed to look like.

    Texture2D actual

    What the image actually looks like.

    ImageComparisonSettings settings

    Optional settings that control how the comparison is performed. Can be null, in which case the images are required to be exactly identical.

    string expectedImagePathLog

    The log message to display if the test fails.

    bool saveFailedImage

    If true, the actual image will be saved if the test fails.

    bool saveFailedImageToDisk

    If true, the actual image will be saved to disk if the test fails.

    bool logMessages

    If true, the log messages will be displayed.

    AreEqual(Texture2D, Texture2D, ImageComparisonSettings, string, bool, bool, bool, out ImageComparisonResults)

    Compares an image to a 'reference' image to see if it looks correct.

    Declaration
    public static void AreEqual(Texture2D expected, Texture2D actual, ImageComparisonSettings settings, string expectedImagePathLog, bool saveFailedImage, bool saveFailedImageToDisk, bool logMessages, out ImageAssert.ImageComparisonResults result)
    Parameters
    Type Name Description
    Texture2D expected

    What the image is supposed to look like.

    Texture2D actual

    What the image actually looks like.

    ImageComparisonSettings settings

    Optional settings that control how the comparison is performed. Can be null, in which case the images are required to be exactly identical.

    string expectedImagePathLog

    The log message to display if the test fails.

    bool saveFailedImage

    If true, the actual image will be saved if the test fails.

    bool saveFailedImageToDisk

    If true, the actual image will be saved to disk if the test fails.

    bool logMessages

    If true, the log messages will be displayed.

    ImageAssert.ImageComparisonResults result

    The result of the image comparison.

    AreEqualAsync(Texture2D, IEnumerable<Camera>, Action<bool>, ImageComparisonSettings, string, bool)

    Render an image from the given cameras and compare it to the reference image.

    Declaration
    public static IEnumerator AreEqualAsync(Texture2D expected, IEnumerable<Camera> cameras, Action<bool> callback = null, ImageComparisonSettings settings = null, string expectedImagePathLog = null, bool saveFailedImageToDisk = false)
    Parameters
    Type Name Description
    Texture2D expected

    The expected image to compare against.

    IEnumerable<Camera> cameras

    The cameras to render from. All cameras will be rendered to the same rendered texture. This is useful when testing camera stacking/overlay.

    Action<bool> callback

    Optional callback with boolean parameter to represent if AreEqual is successful

    ImageComparisonSettings settings

    Optional settings that control how the image comparison is performed. Can be null, in which case the rendered image is required to be exactly identical to the reference.

    string expectedImagePathLog

    The log message to display if the test fails.

    bool saveFailedImageToDisk

    If true, the actual image will be saved to disk if the test fails.

    Returns
    Type Description
    IEnumerator

    An enumerator that can be used to wait for the image comparison to complete.

    AreEqualLinearHDR(Texture2D, Texture2D, ImageComparisonSettings, string, bool, bool)

    Compares an image to a 'reference' image to see if it looks correct. Assumes linear HDR images (RGBAFloat or RGBAHalf).

    Declaration
    public static void AreEqualLinearHDR(Texture2D expected, Texture2D actual, ImageComparisonSettings settings = null, string expectedImagePathLog = null, bool saveFailedImage = true, bool saveFailedImageToDisk = false)
    Parameters
    Type Name Description
    Texture2D expected

    What the image is supposed to look like.

    Texture2D actual

    What the image actually looks like.

    ImageComparisonSettings settings

    Optional settings that control how the comparison is performed. Can be null, in which case the images are required to be exactly identical.

    string expectedImagePathLog

    The log message to display if the test fails.

    bool saveFailedImage

    If true, the actual image will be saved if the test fails.

    bool saveFailedImageToDisk

    If true, the actual image will be saved to disk if the test fails.

    CheckGCAllocWithCallstack(Camera, ImageComparisonSettings, string)

    Render an image from the given camera and check if it allocated memory while doing so. Also outputs the callstack of the GC.Alloc found

    Declaration
    public static IEnumerator CheckGCAllocWithCallstack(Camera camera, ImageComparisonSettings settings = null, string overrideSrpMarkerName = null)
    Parameters
    Type Name Description
    Camera camera

    The camera to render from.

    ImageComparisonSettings settings

    Settings to create the camera render target

    string overrideSrpMarkerName

    Override the main marker used to check the GC.Alloc

    Returns
    Type Description
    IEnumerator

    An enumerator that can be used to wait for the operation to complete.

    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)