A game about forced loneliness, made by TACStudios
at master 3.1 kB view raw
1using System; 2 3namespace UnityEngine.TestTools 4{ 5 /// <summary> 6 /// PrebuildSetup attribute run if the test or test class is in the current test run. The test is included either by running all tests or setting a filter that includes the test. If multiple tests reference the same pre-built setup or post-build cleanup, then it only runs once. 7 /// </summary> 8 [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] 9 public class PrebuildSetupAttribute : Attribute 10 { 11 /// <summary> 12 /// Initializes and returns an instance of PrebuildSetupAttribute by type. 13 /// </summary> 14 /// <param name="targetClass">The type of the target class.</param> 15 public PrebuildSetupAttribute(Type targetClass) 16 { 17 TargetClass = targetClass; 18 } 19 20 /// <summary> 21 /// 22 /// </summary> 23 /// <param name="targetClassName"></param> 24 /// <example> 25 /// <code> 26 /// [TestFixture] 27 /// public class CreateSpriteTest : IPrebuildSetup 28 /// { 29 /// Texture2D m_Texture; 30 /// Sprite m_Sprite; 31 /// 32 /// public void Setup() 33 /// { 34 /// 35 /// #if UNITY_EDITOR 36 /// 37 /// var spritePath = "Assets/Resources/Circle.png"; 38 /// var ti = UnityEditor.AssetImporter.GetAtPath(spritePath) as UnityEditor.TextureImporter; 39 /// ti.textureCompression = UnityEditor.TextureImporterCompression.Uncompressed; 40 /// ti.SaveAndReimport(); 41 /// 42 /// #endif 43 /// } 44 /// 45 /// [SetUp] 46 /// public void SetUpTest() 47 /// { 48 /// m_Texture = Resources.Load&lt;Texture2D&gt;("Circle"); 49 /// } 50 /// 51 /// [Test] 52 /// public void WhenNullTextureIsPassed_CreateShouldReturnNullSprite() 53 /// { 54 /// 55 /// // Check with Valid Texture. 56 /// LogAssert.Expect(LogType.Log, "Circle Sprite Created"); 57 /// Sprite.Create(m_Texture, new Rect(0, 0, m_Texture.width, m_Texture.height), new Vector2(0.5f, 0.5f)); 58 /// Debug.Log("Circle Sprite Created"); 59 /// 60 /// // Check with NULL Texture. Should return NULL Sprite. 61 /// m_Sprite = Sprite.Create(null, new Rect(0, 0, m_Texture.width, m_Texture.heig`t), new Vector2(0.5f, 0.5f)); 62 /// Assert.That(m_Sprite, Is.Null, "Sprite created with null texture should be null"); 63 /// } 64 /// } 65 /// </code> 66 /// Tip: Use `#if UNITY_EDITOR` if you want to access Editor only APIs, but the setup/cleanup is inside a **Play Mode** assembly. 67 /// </example> 68 public PrebuildSetupAttribute(string targetClassName) 69 { 70 TargetClass = AttributeHelper.GetTargetClassFromName(targetClassName, typeof(IPrebuildSetup)); 71 } 72 73 internal Type TargetClass { get; private set; } 74 } 75}