Version: 2018.3 (switch to 2019.1)
LanguageEnglish
  • C#

Is

class in UnityEngine.TestTools.Constraints

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

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 Methods

AllocatingGCMemoryDeclares a constraint that the provided delegate allocates GC memory.

Did you find this page useful? Please give it a rating: