AllocatingGCMemoryConstraint

class in UnityEngine.TestTools.Constraints

매뉴얼로 전환

설명

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

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:

using NUnit.Framework;
using UnityEngine.TestTools.Constraints;
using Is = UnityEngine.TestTools.Constraints.Is;

public class MyTestClass { [Test] public void SettingAVariableDoesNotAllocate() { Assert.That(() => { int a = 0; a = 1; }, Is.Not.AllocatingGCMemory()); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961