reference-attribute-conditionalignore.md 1.05 KB
Newer Older
BlackAngle233's avatar
212    
BlackAngle233 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# ConditionalIgnore attribute

This attribute is an alternative to the standard `Ignore` attribute in [NUnit](http://www.nunit.org/). It allows for ignoring tests only under a specified condition. The condition evaluates during `OnLoad`, referenced by ID. 

## Example

The following example shows a method to use the `ConditionalIgnore` attribute to ignore a test if the Unity Editor is running macOS:

```C#
using UnityEditor;
using NUnit.Framework;
using UnityEngine.TestTools;

[InitializeOnLoad]
public class OnLoad
{
    static OnLoad()
    {
        var editorIsOSX = false;
        #if UNITY_EDITOR_OSX
            editorIsOSX = true;
        #endif
        
        ConditionalIgnoreAttribute.AddConditionalIgnoreMapping("IgnoreInMacEditor", editorIsOSX);
    }
}

public class MyTestClass
{
    [Test, ConditionalIgnore("IgnoreInMacEditor", "Ignored on Mac editor.")]
    public void TestNeverRunningInMacEditor()
    {
        Assert.Pass();
    }
}

```

BlackAngle233's avatar
BlackAngle233 committed
39
> **Note**: You can only use `InitializeOnLoad` in **Edit Mode** tests.