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
.