Skip to content

Commit

Permalink
Split test script between editor and runtime folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Verasl committed Oct 20, 2021
1 parent 040c149 commit 42f9e9e
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.TestTools.Graphics;
using UnityEngine.SceneManagement;
using UnityEditor;
using UnityEditor.TestTools.Graphics;

public class BoatAttackGraphicsTestsEditor : IPrebuildSetup, IPostBuildCleanup
{
private const string DefineKey = "BoatAttack_Tests_ScriptingDefines";
private static float _oldTimeScale = 1.0f; // give default of 1 just in case

public void Setup()
{
// save current scription defines and set both STATIC_EVERYTHING and LWRP_DEBUG_STATIC_POSTFX
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
EditorPrefs.SetString(DefineKey, defines);
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, "STATIC_EVERYTHING;LWRP_DEBUG_STATIC_POSTFX");
// store current timescale and set it to 0
_oldTimeScale = Time.timeScale;
Time.timeScale = 0f;
// run base graphics test setup
SetupGraphicsTestCases.Setup();
}


public void Cleanup()
{
EditorApplication.delayCall += FinalCall;
Time.timeScale = _oldTimeScale;
Shader.DisableKeyword("_STATIC_SHADER");
}

private static void FinalCall()
{
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, EditorPrefs.GetString(DefineKey));
EditorPrefs.DeleteKey(DefineKey);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "UnityGFXTests.Editor.BoatAttack",
"rootNamespace": "",
"references": [
"GUID:c081bc530f560634bb5c21d4b323a7f1",
"GUID:0acc523941302664db1f4e527237feb3",
"GUID:27619889b8ba8c24980f49ee34dbb44a",
"GUID:e18141520846dcc44b725b2f74e91229"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 2 additions & 36 deletions Assets/Scripts/UnityGFXTests/Runtime/BoatAttackGraphicsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,9 @@
using UnityEngine.TestTools;
using UnityEngine.TestTools.Graphics;
using UnityEngine.SceneManagement;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.TestTools.Graphics;
#endif

public class BoatAttackGraphicsTests : IPrebuildSetup, IPostBuildCleanup
public class BoatAttackGraphicsTests
{
private const string DefineKey = "BoatAttack_Tests_ScriptingDefines";
private static float _oldTimeScale = 1.0f; // give default of 1 just in case

#if UNITY_EDITOR
public void Setup()
{
// save current scription defines and set both STATIC_EVERYTHING and LWRP_DEBUG_STATIC_POSTFX
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
EditorPrefs.SetString(DefineKey, defines);
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, "STATIC_EVERYTHING;LWRP_DEBUG_STATIC_POSTFX");
// store current timescale and set it to 0
_oldTimeScale = Time.timeScale;
Time.timeScale = 0f;
// run base graphics test setup
SetupGraphicsTestCases.Setup();
}
#endif

[UnityTest, Category("BoatAttack")]
[UseGraphicsTestCases]
Expand Down Expand Up @@ -73,20 +52,7 @@ private static BoatAttackGraphicsTestsSettings SetTestSettings(BoatAttackGraphic
[TearDown]
public void DumpImagesInEditor()
{
ResultsUtility.ExtractImagesFromTestProperties(TestContext.CurrentContext.Test);
}

public void Cleanup()
{
EditorApplication.delayCall += FinalCall;
Time.timeScale = _oldTimeScale;
Shader.DisableKeyword("_STATIC_SHADER");
}

private static void FinalCall()
{
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, EditorPrefs.GetString(DefineKey));
EditorPrefs.DeleteKey(DefineKey);
UnityEditor.TestTools.Graphics.ResultsUtility.ExtractImagesFromTestProperties(TestContext.CurrentContext.Test);
}
#endif
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"rootNamespace": "",
"references": [
"GUID:c081bc530f560634bb5c21d4b323a7f1",
"GUID:0acc523941302664db1f4e527237feb3",
"GUID:27619889b8ba8c24980f49ee34dbb44a",
"GUID:e18141520846dcc44b725b2f74e91229"
"GUID:27619889b8ba8c24980f49ee34dbb44a"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand All @@ -14,7 +12,7 @@
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": true,
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 42f9e9e

Please sign in to comment.