{!See https://docs.google.com/document/d/1takg_GmIBBKKTj-GHZCwzxohpQz7Bhekivkk72kYMtE/edit for reference implementation of OneTrust, dataLayer and GTM} {!OneTrust Cookies Consent} {!OneTrust Cookies Consent end} {!dataLayer initialization push} {!dataLayer initialization push end} {!Google Tag Manager} {!Google Tag Manager end} Namespace UnityEngine.TestTools.Constraints | Test Framework | 2.0.1-exp.2
docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Namespace UnityEngine.TestTools.Constraints

    Classes

    AllocatingGCMemoryConstraint

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

    Use this class 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 has caused any GC memory to be allocated. If any GC memory was allocated, the constraint passes; otherwise, the constraint fails.

    Be careful to take into account that there may be GC allocations that happen only on the first time your code is run, such as initialization of static variables. If you want to measure a 'typical' execution of your code, you may want to deliberately execute it once before testing it with this constraint, so that any one-time allocations have already been performed before this constraint measures it.

    Usually you negate this constraint to make sure that your delegate does not allocate any GC memory. This is easy to do using the Is class:

    ConstraintExtensions

    Is

    NUnit allows you to write test assertions in a more descriptive and human readable way using the Assert.That mechanism, where the first parameter is an object under test and the second parameter describes conditions that the object has to meet.

    We have extended NUnit API with a custom constraint type and declared an overlay Is class. To resolve ambiguity between the original implementation and the custom one you must explicitly declare it with a using statement or via addressing through the full type name UnityEngine.TestTools.Constraints.Is.

    In This Article
    Back to top
    Copyright © 2023 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)