# Assert

> The Assert class contains assertion methods for setting invariants in the code.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine.Assertions](/engine/6000.0/script-reference/unityengine/assertions.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public static class Assert
```

## Remarks

All method calls will be conditionally included only in a development build, unless specified explicitly. See [BuildOptions.ForceEnableAssertions](/engine/6000.0/script-reference/unityeditor/buildoptions/forceenableassertions.md). The inclusion of an assertion is controlled by the UNITY\_ASSERTIONS define.

Assert throws exceptions whenever an assertion fails.

If a debugger is attached to the project (System.Diagnostics.Debugger.IsAttached is true), [AssertionException](/engine/6000.0/script-reference/unityengine/assertions/assertionexception.md) is thrown to pause the execution and invoke the debugger.

## Examples

```csharp
using UnityEngine;
using UnityEngine.Assertions;

public class AssertionExampleClass : MonoBehaviour
{
    public int health;
    public GameObject go;

    void Update()
    {
        // You expect the health never to be equal to zero
        Assert.AreNotEqual(0, health);

        // The referenced GameObject should be always (in every frame) be active
        Assert.IsTrue(go.activeInHierarchy);
    }
}
```

## Static Methods

| Method                                                                                                                | Description                                                       |
| --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| [AreApproximatelyEqual](/engine/6000.0/script-reference/unityengine/assertions/assert/areapproximatelyequal.md)       | Assert the values are approximately equal.                        |
| [AreEqual](/engine/6000.0/script-reference/unityengine/assertions/assert/areequal.md)                                 | Assert that the values are equal.                                 |
| [AreNotApproximatelyEqual](/engine/6000.0/script-reference/unityengine/assertions/assert/arenotapproximatelyequal.md) | Asserts that the values are approximately not equal.              |
| [AreNotEqual](/engine/6000.0/script-reference/unityengine/assertions/assert/arenotequal.md)                           | Assert that the values are not equal.                             |
| [IsFalse](/engine/6000.0/script-reference/unityengine/assertions/assert/isfalse.md)                                   | Return true when the condition is false.  Otherwise return false. |
| [IsNotNull](/engine/6000.0/script-reference/unityengine/assertions/assert/isnotnull.md)                               | Assert that the value is not null.                                |
| [IsNull](/engine/6000.0/script-reference/unityengine/assertions/assert/isnull.md)                                     | Assert the value is null.                                         |
| [IsTrue](/engine/6000.0/script-reference/unityengine/assertions/assert/istrue.md)                                     | Asserts that the condition is true.                               |
