{!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} Custom constraints | Test Framework | 1.0.18
docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Custom constraints

    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.

    Is

    We’ve 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.

    Static Methods

    Syntax Description
    AllocatingGCMemory A constraint type that invokes the delegate you provide as the parameter of Assert.That and checks whether it causes any GC memory allocations. It passes if any GC memory is allocated and fails if not.

    Example

    using Is = UnityEngine.TestTools.Constraints.Is;
    
    class MyTestClass
    {
        [Test]
        public void MyTest()
        {
            Assert.That(() => {
                var i = new int[500];
            }, Is.AllocatingGCMemory());
        }
    }
    
    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)