Skip to content

Commit 42f9e9e

Browse files
committed
Split test script between editor and runtime folders
1 parent 040c149 commit 42f9e9e

8 files changed

+88
-42
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Collections;
2+
using NUnit.Framework;
3+
using UnityEngine;
4+
using UnityEngine.TestTools;
5+
using UnityEngine.TestTools.Graphics;
6+
using UnityEngine.SceneManagement;
7+
using UnityEditor;
8+
using UnityEditor.TestTools.Graphics;
9+
10+
public class BoatAttackGraphicsTestsEditor : IPrebuildSetup, IPostBuildCleanup
11+
{
12+
private const string DefineKey = "BoatAttack_Tests_ScriptingDefines";
13+
private static float _oldTimeScale = 1.0f; // give default of 1 just in case
14+
15+
public void Setup()
16+
{
17+
// save current scription defines and set both STATIC_EVERYTHING and LWRP_DEBUG_STATIC_POSTFX
18+
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
19+
EditorPrefs.SetString(DefineKey, defines);
20+
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, "STATIC_EVERYTHING;LWRP_DEBUG_STATIC_POSTFX");
21+
// store current timescale and set it to 0
22+
_oldTimeScale = Time.timeScale;
23+
Time.timeScale = 0f;
24+
// run base graphics test setup
25+
SetupGraphicsTestCases.Setup();
26+
}
27+
28+
29+
public void Cleanup()
30+
{
31+
EditorApplication.delayCall += FinalCall;
32+
Time.timeScale = _oldTimeScale;
33+
Shader.DisableKeyword("_STATIC_SHADER");
34+
}
35+
36+
private static void FinalCall()
37+
{
38+
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, EditorPrefs.GetString(DefineKey));
39+
EditorPrefs.DeleteKey(DefineKey);
40+
}
41+
}

Assets/Scripts/UnityGFXTests/Editor/BoatAttackGraphicsTestsEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "UnityGFXTests.Editor.BoatAttack",
3+
"rootNamespace": "",
4+
"references": [
5+
"GUID:c081bc530f560634bb5c21d4b323a7f1",
6+
"GUID:0acc523941302664db1f4e527237feb3",
7+
"GUID:27619889b8ba8c24980f49ee34dbb44a",
8+
"GUID:e18141520846dcc44b725b2f74e91229"
9+
],
10+
"includePlatforms": [
11+
"Editor"
12+
],
13+
"excludePlatforms": [],
14+
"allowUnsafeCode": false,
15+
"overrideReferences": true,
16+
"precompiledReferences": [
17+
"nunit.framework.dll"
18+
],
19+
"autoReferenced": true,
20+
"defineConstraints": [],
21+
"versionDefines": [],
22+
"noEngineReferences": false
23+
}

Assets/Scripts/UnityGFXTests/Editor/UnityGFXTests.BoatAttack.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/UnityGFXTests/Runtime/BoatAttackGraphicsTests.cs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,9 @@
44
using UnityEngine.TestTools;
55
using UnityEngine.TestTools.Graphics;
66
using UnityEngine.SceneManagement;
7-
#if UNITY_EDITOR
8-
using UnityEditor;
9-
using UnityEditor.TestTools.Graphics;
10-
#endif
117

12-
public class BoatAttackGraphicsTests : IPrebuildSetup, IPostBuildCleanup
8+
public class BoatAttackGraphicsTests
139
{
14-
private const string DefineKey = "BoatAttack_Tests_ScriptingDefines";
15-
private static float _oldTimeScale = 1.0f; // give default of 1 just in case
16-
17-
#if UNITY_EDITOR
18-
public void Setup()
19-
{
20-
// save current scription defines and set both STATIC_EVERYTHING and LWRP_DEBUG_STATIC_POSTFX
21-
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
22-
EditorPrefs.SetString(DefineKey, defines);
23-
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, "STATIC_EVERYTHING;LWRP_DEBUG_STATIC_POSTFX");
24-
// store current timescale and set it to 0
25-
_oldTimeScale = Time.timeScale;
26-
Time.timeScale = 0f;
27-
// run base graphics test setup
28-
SetupGraphicsTestCases.Setup();
29-
}
30-
#endif
3110

3211
[UnityTest, Category("BoatAttack")]
3312
[UseGraphicsTestCases]
@@ -73,20 +52,7 @@ private static BoatAttackGraphicsTestsSettings SetTestSettings(BoatAttackGraphic
7352
[TearDown]
7453
public void DumpImagesInEditor()
7554
{
76-
ResultsUtility.ExtractImagesFromTestProperties(TestContext.CurrentContext.Test);
77-
}
78-
79-
public void Cleanup()
80-
{
81-
EditorApplication.delayCall += FinalCall;
82-
Time.timeScale = _oldTimeScale;
83-
Shader.DisableKeyword("_STATIC_SHADER");
84-
}
85-
86-
private static void FinalCall()
87-
{
88-
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, EditorPrefs.GetString(DefineKey));
89-
EditorPrefs.DeleteKey(DefineKey);
55+
UnityEditor.TestTools.Graphics.ResultsUtility.ExtractImagesFromTestProperties(TestContext.CurrentContext.Test);
9056
}
9157
#endif
9258
}

Assets/Scripts/UnityGFXTests/Runtime/BoatAttackGraphicsTests.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/UnityGFXTests/Runtime/UnityGFXTests.BoatAttack.asmdef

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"rootNamespace": "",
44
"references": [
55
"GUID:c081bc530f560634bb5c21d4b323a7f1",
6-
"GUID:0acc523941302664db1f4e527237feb3",
7-
"GUID:27619889b8ba8c24980f49ee34dbb44a",
8-
"GUID:e18141520846dcc44b725b2f74e91229"
6+
"GUID:27619889b8ba8c24980f49ee34dbb44a"
97
],
108
"includePlatforms": [],
119
"excludePlatforms": [],
@@ -14,7 +12,7 @@
1412
"precompiledReferences": [
1513
"nunit.framework.dll"
1614
],
17-
"autoReferenced": true,
15+
"autoReferenced": false,
1816
"defineConstraints": [
1917
"UNITY_INCLUDE_TESTS"
2018
],

Assets/Scripts/UnityGFXTests/Runtime/UnityGFXTests.BoatAttack.asmdef.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)