SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.3 KiB

4 years ago
  1. # Custom constraints
  2. `NUnit` allows you to write test assertions in a more descriptive and human readable way using the [Assert.That](https://github.com/nunit/docs/wiki/Assertions) mechanism, where the first parameter is an object under test and the second parameter describes conditions that the object has to meet.
  3. ## Is
  4. 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`.
  5. ### Static Methods
  6. | Syntax | Description |
  7. | -------------------- | ------------------------------------------------------------ |
  8. | `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. |
  9. ## Example
  10. ```c#
  11. using Is = UnityEngine.TestTools.Constraints.Is;
  12. class MyTestClass
  13. {
  14. [Test]
  15. public void MyTest()
  16. {
  17. Assert.That(() => {
  18. var i = new int[500];
  19. }, Is.AllocatingGCMemory());
  20. }
  21. }
  22. ```