Is

class in UnityEngine.TestTools.Constraints

Switch to Manual

Description

Provides Unity-specific constraint types for use with NUnit's Assert.That method.

NUnit allows test authors to write assertions using the Assert.That() method, where the first parameter is the object under test, and the second parameter describes the conditions that the object has to meet. These can often be expressed in a human-readable style, for example Assert.That(3, Is.Not.EqualTo(2)).

Unity extends NUnit's mechanisms with some custom Unity-specific constraint types, and declares this "Is" class as an overlay on top of NUnit's. To resolve ambiguity between NUnit's own Is class and Unity's, you must explicitly declare it in a using statement, like this:

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

class MyTestClass { [Test] public void MyTest() { Assert.That(() => { var i = new int[500]; }, Is.AllocatingGCMemory()); } }

Static Functions

AllocatingGCMemoryDeclares a constraint that the provided delegate allocates GC memory.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961