docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class ConstraintExtensions

    An NUnit test constraint class to test whether a given block of code makes any GC allocations.

    Inheritance
    object
    ConstraintExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.TestTools.Constraints
    Assembly: UnityEngine.TestRunner.dll
    Syntax
    public static class ConstraintExtensions

    Methods

    AllocatingGCMemory(ConstraintExpression)

    Use this with NUnit's Assert.That() method to make assertions about the GC behaviour of your code. The constraint executes the delegate you provide, and checks if it caused any GC memory to be allocated. If any GC memory was allocated, the constraint passes; otherwise, the constraint fails. See https://docs.unity3d.com/Packages/com.unity.test-framework@1.1/api/UnityEngine.TestTools.Constraints.AllocatingGCMemoryConstraint.html for an example.

    Declaration
    public static AllocatingGCMemoryConstraint AllocatingGCMemory(this ConstraintExpression chain)
    Parameters
    Type Name Description
    ConstraintExpression chain
    Returns
    Type Description
    AllocatingGCMemoryConstraint
    In This Article
    Back to top
    Copyright © 2025 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)