Browse Source

Fix Unity Test Tools to run in 5.0

master
chrisgregan 9 years ago
parent
commit
d7f6ef7b91
  1. 4
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/MenuItems.cs
  2. 9
      Assets/Tests/UI/Editor/TextTagParserTests.cs
  3. 8
      Assets/UnityTestTools/Assertions/Editor/AssertionComponentEditor.cs
  4. 4
      Assets/UnityTestTools/Assertions/Editor/AssertionExplorerWindow.cs
  5. 8
      Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/Batch.cs
  6. 14
      Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/IntegrationTestsRunnerWindow.cs
  7. 4
      Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/NetworkResultsReceiver.cs
  8. 11
      Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerConfiguration.cs
  9. 15
      Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerSettingsWindow.cs
  10. 6
      Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/TestComponentEditor.cs
  11. 8
      Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/ResultDTO.cs
  12. 6
      Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestComponent.cs
  13. 19
      Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunner.cs

4
Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/MenuItems.cs vendored

@ -44,7 +44,11 @@ namespace Fungus
File.WriteAllText(path, ""); File.WriteAllText(path, "");
AssetDatabase.Refresh(); AssetDatabase.Refresh();
#if UNITY_5_3_OR_NEWER
Object asset = AssetDatabase.LoadAssetAtPath<Object>(path); Object asset = AssetDatabase.LoadAssetAtPath<Object>(path);
#else
Object asset = AssetDatabase.LoadAssetAtPath(path, typeof(Object));
#endif
if (asset != null) if (asset != null)
{ {
EditorUtility.FocusProjectWindow(); EditorUtility.FocusProjectWindow();

9
Assets/Tests/UI/Editor/TextTagParserTests.cs

@ -1,10 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine; using UnityEngine;
using Fungus; using Fungus;
#if UNITY_5_3_OR_NEWER
using NUnit.Framework;
[TestFixture] [TestFixture]
public class TextTagParserTests public class TextTagParserTests
{ {
@ -217,3 +220,5 @@ public class TextTagParserTests
} }
} }
#endif

8
Assets/UnityTestTools/Assertions/Editor/AssertionComponentEditor.cs

@ -4,7 +4,9 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
#if UNITY_5_3_OR_NEWER
using UnityEditor.SceneManagement; using UnityEditor.SceneManagement;
#endif
namespace UnityTest namespace UnityTest
{ {
@ -83,7 +85,13 @@ namespace UnityTest
} }
} }
if(GUI.changed) if(GUI.changed)
{
#if UNITY_5_3_OR_NEWER
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
#else
EditorApplication.MarkSceneDirty();
#endif
}
} }
private void DrawOptionsForAfterPeriodOfTime(AssertionComponent script) private void DrawOptionsForAfterPeriodOfTime(AssertionComponent script)

4
Assets/UnityTestTools/Assertions/Editor/AssertionExplorerWindow.cs

@ -32,7 +32,11 @@ namespace UnityTest
public AssertionExplorerWindow() public AssertionExplorerWindow()
{ {
#if UNITY_5_3_OR_NEWER
titleContent = new GUIContent("Assertion Explorer"); titleContent = new GUIContent("Assertion Explorer");
#else
title = "Assertion Explorer";
#endif
} }
public void OnDidOpenScene() public void OnDidOpenScene()

8
Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/Batch.cs

@ -6,7 +6,10 @@ using UnityEditor;
using UnityEditorInternal; using UnityEditorInternal;
using UnityEngine; using UnityEngine;
using UnityTest.IntegrationTests; using UnityTest.IntegrationTests;
#if UNITY_5_3_OR_NEWER
using UnityEditor.SceneManagement; using UnityEditor.SceneManagement;
#endif
namespace UnityTest namespace UnityTest
{ {
@ -99,7 +102,12 @@ namespace UnityTest
} }
EditorBuildSettings.scenes = (testScenes.Concat(otherBuildScenes).ToList()).Select(s => new EditorBuildSettingsScene(s, true)).ToArray(); EditorBuildSettings.scenes = (testScenes.Concat(otherBuildScenes).ToList()).Select(s => new EditorBuildSettingsScene(s, true)).ToArray();
#if UNITY_5_3_OR_NEWER
EditorSceneManager.OpenScene(testScenes.First()); EditorSceneManager.OpenScene(testScenes.First());
#else
EditorApplication.LoadLevelInPlayMode(testScenes.First());
#endif
GuiHelper.SetConsoleErrorPause(false); GuiHelper.SetConsoleErrorPause(false);
var config = new PlatformRunnerConfiguration var config = new PlatformRunnerConfiguration

14
Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/IntegrationTestsRunnerWindow.cs

@ -6,7 +6,9 @@ using System.Text.RegularExpressions;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityTest.IntegrationTestRunner; using UnityTest.IntegrationTestRunner;
#if UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
#endif
namespace UnityTest namespace UnityTest
{ {
@ -84,7 +86,11 @@ namespace UnityTest
private static void BackgroundSceneChangeWatch() private static void BackgroundSceneChangeWatch()
{ {
if (!s_Instance) return; if (!s_Instance) return;
#if UNITY_5_3_OR_NEWER
var currentScene = SceneManager.GetActiveScene().path; var currentScene = SceneManager.GetActiveScene().path;
#else
var currentScene = Application.loadedLevelName;
#endif
if (s_Instance.m_CurrectSceneName != null && s_Instance.m_CurrectSceneName == currentScene) return; if (s_Instance.m_CurrectSceneName != null && s_Instance.m_CurrectSceneName == currentScene) return;
if (EditorApplication.isPlayingOrWillChangePlaymode) return; if (EditorApplication.isPlayingOrWillChangePlaymode) return;
TestComponent.DestroyAllDynamicTests(); TestComponent.DestroyAllDynamicTests();
@ -95,7 +101,11 @@ namespace UnityTest
public void OnEnable() public void OnEnable()
{ {
#if UNITY_5_3_OR_NEWER
titleContent = new GUIContent("Integration Tests"); titleContent = new GUIContent("Integration Tests");
#else
title = "Integration Tests";
#endif
s_Instance = this; s_Instance = this;
m_Settings = ProjectSettingsBase.Load<IntegrationTestsRunnerSettings>(); m_Settings = ProjectSettingsBase.Load<IntegrationTestsRunnerSettings>();
@ -241,7 +251,11 @@ namespace UnityTest
if (!EditorApplication.isPlayingOrWillChangePlaymode) if (!EditorApplication.isPlayingOrWillChangePlaymode)
{ {
var dynamicTestsOnScene = TestComponent.FindAllDynamicTestsOnScene(); var dynamicTestsOnScene = TestComponent.FindAllDynamicTestsOnScene();
#if UNITY_5_3_OR_NEWER
var dynamicTestTypes = TestComponent.GetTypesWithHelpAttribute(SceneManager.GetActiveScene().path); var dynamicTestTypes = TestComponent.GetTypesWithHelpAttribute(SceneManager.GetActiveScene().path);
#else
var dynamicTestTypes = TestComponent.GetTypesWithHelpAttribute(Application.loadedLevelName);
#endif
foreach (var dynamicTestType in dynamicTestTypes) foreach (var dynamicTestType in dynamicTestTypes)
{ {

4
Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/NetworkResultsReceiver.cs

@ -177,7 +177,11 @@ namespace UnityTest
public void OnEnable() public void OnEnable()
{ {
minSize = new Vector2(300, 100); minSize = new Vector2(300, 100);
#if UNITY_5_3_OR_NEWER
titleContent = new GUIContent("Test run monitor"); titleContent = new GUIContent("Test run monitor");
#else
title = "Test run monitor";
#endif
Instance = this; Instance = this;
m_StatusLabel = "Initializing..."; m_StatusLabel = "Initializing...";
if (EditorApplication.isCompiling) return; if (EditorApplication.isCompiling) return;

11
Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerConfiguration.cs

@ -6,7 +6,10 @@ using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
#if UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
#endif
[Serializable] [Serializable]
public class PlatformRunnerConfiguration public class PlatformRunnerConfiguration
@ -15,7 +18,11 @@ public class PlatformRunnerConfiguration
public List<string> testScenes; public List<string> testScenes;
public BuildTarget buildTarget; public BuildTarget buildTarget;
public bool runInEditor; public bool runInEditor;
#if UNITY_5_3_OR_NEWER
public string projectName = SceneManager.GetActiveScene().path; public string projectName = SceneManager.GetActiveScene().path;
#else
public string projectName = Application.loadedLevelName;
#endif
public string resultsDir = null; public string resultsDir = null;
public bool sendResultsOverNetwork; public bool sendResultsOverNetwork;
@ -25,7 +32,11 @@ public class PlatformRunnerConfiguration
public PlatformRunnerConfiguration(BuildTarget buildTarget) public PlatformRunnerConfiguration(BuildTarget buildTarget)
{ {
this.buildTarget = buildTarget; this.buildTarget = buildTarget;
#if UNITY_5_3_OR_NEWER
projectName = SceneManager.GetActiveScene().path; projectName = SceneManager.GetActiveScene().path;
#else
projectName = Application.loadedLevelName;
#endif
} }
public PlatformRunnerConfiguration() public PlatformRunnerConfiguration()

15
Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerSettingsWindow.cs

@ -6,7 +6,9 @@ using System.Net;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using Object = UnityEngine.Object; using Object = UnityEngine.Object;
#if UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
#endif
namespace UnityTest.IntegrationTests namespace UnityTest.IntegrationTests
{ {
@ -43,12 +45,21 @@ namespace UnityTest.IntegrationTests
if (m_IntegrationTestScenes == null) if (m_IntegrationTestScenes == null)
m_IntegrationTestScenes = new List<string> (); m_IntegrationTestScenes = new List<string> ();
#if UNITY_5_3_OR_NEWER
titleContent = new GUIContent("Platform runner"); titleContent = new GUIContent("Platform runner");
#else
title = "Platform runner";
#endif
m_BuildTarget = PlatformRunner.defaultBuildTarget; m_BuildTarget = PlatformRunner.defaultBuildTarget;
position.Set(position.xMin, position.yMin, 200, position.height); position.Set(position.xMin, position.yMin, 200, position.height);
m_AllScenesInProject = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.unity", SearchOption.AllDirectories).ToList(); m_AllScenesInProject = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.unity", SearchOption.AllDirectories).ToList();
m_AllScenesInProject.Sort(); m_AllScenesInProject.Sort();
#if UNITY_5_3_OR_NEWER
var currentScene = (Directory.GetCurrentDirectory() + SceneManager.GetActiveScene().path).Replace("\\", "").Replace("/", ""); var currentScene = (Directory.GetCurrentDirectory() + SceneManager.GetActiveScene().path).Replace("\\", "").Replace("/", "");
#else
var currentScene = (Directory.GetCurrentDirectory() + Application.loadedLevelName).Replace("\\", "").Replace("/", "");
#endif
var currentScenePath = m_AllScenesInProject.Where(s => s.Replace("\\", "").Replace("/", "") == currentScene); var currentScenePath = m_AllScenesInProject.Where(s => s.Replace("\\", "").Replace("/", "") == currentScene);
m_SelectedScenes.AddRange(currentScenePath); m_SelectedScenes.AddRange(currentScenePath);
@ -267,7 +278,11 @@ namespace UnityTest.IntegrationTests
buildTarget = m_BuildTarget, buildTarget = m_BuildTarget,
buildScenes = m_OtherScenesToBuild, buildScenes = m_OtherScenesToBuild,
testScenes = m_IntegrationTestScenes, testScenes = m_IntegrationTestScenes,
#if UNITY_5_3_OR_NEWER
projectName = m_IntegrationTestScenes.Count > 1 ? "IntegrationTests" : Path.GetFileNameWithoutExtension(SceneManager.GetActiveScene().path), projectName = m_IntegrationTestScenes.Count > 1 ? "IntegrationTests" : Path.GetFileNameWithoutExtension(SceneManager.GetActiveScene().path),
#else
projectName = m_IntegrationTestScenes.Count > 1 ? "IntegrationTests" : Path.GetFileNameWithoutExtension(Application.loadedLevelName),
#endif
resultsDir = m_Settings.resultsPath, resultsDir = m_Settings.resultsPath,
sendResultsOverNetwork = m_Settings.sendResultsOverNetwork, sendResultsOverNetwork = m_Settings.sendResultsOverNetwork,
ipList = m_Interfaces.Skip(1).ToList(), ipList = m_Interfaces.Skip(1).ToList(),

6
Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/TestComponentEditor.cs

@ -4,7 +4,9 @@ using System.Linq;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using Object = UnityEngine.Object; using Object = UnityEngine.Object;
#if UNITY_5_3_OR_NEWER
using UnityEditor.SceneManagement; using UnityEditor.SceneManagement;
#endif
namespace UnityTest namespace UnityTest
{ {
@ -103,7 +105,11 @@ namespace UnityTest
if (!component.dynamic) if (!component.dynamic)
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
if (GUI.changed) if (GUI.changed)
#if UNITY_5_3_OR_NEWER
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
#else
EditorApplication.MarkSceneDirty();
#endif
} }
private string[] GetListOfIgnoredPlatforms(string[] enumList, int flags) private string[] GetListOfIgnoredPlatforms(string[] enumList, int flags)

8
Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/ResultDTO.cs

@ -1,7 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
#if UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
#endif
namespace UnityTest namespace UnityTest
{ {
@ -19,9 +21,15 @@ namespace UnityTest
private ResultDTO(MessageType messageType) private ResultDTO(MessageType messageType)
{ {
this.messageType = messageType; this.messageType = messageType;
#if UNITY_5_3_OR_NEWER
levelCount = UnityEngine.SceneManagement.SceneManager.sceneCount; levelCount = UnityEngine.SceneManagement.SceneManager.sceneCount;
loadedLevel = UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex; loadedLevel = UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex;
loadedLevelName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; loadedLevelName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
#else
levelCount = Application.levelCount;
loadedLevel = Application.loadedLevel;
loadedLevelName = Application.loadedLevelName;
#endif
} }
public enum MessageType : byte public enum MessageType : byte

6
Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestComponent.cs

@ -3,7 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using UnityEngine; using UnityEngine;
#if UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
#endif
#if UNITY_EDITOR #if UNITY_EDITOR
using UnityEditor; using UnityEditor;
@ -308,10 +310,10 @@ namespace UnityTest
public static bool AnyDynamicTestForCurrentScene() public static bool AnyDynamicTestForCurrentScene()
{ {
#if UNITY_EDITOR #if UNITY_5_3_OR_NEWER
return TestComponent.GetTypesWithHelpAttribute(SceneManager.GetActiveScene().name).Any(); return TestComponent.GetTypesWithHelpAttribute(SceneManager.GetActiveScene().name).Any();
#else #else
return TestComponent.GetTypesWithHelpAttribute(SceneManager.GetActiveScene().name).Any(); return TestComponent.GetTypesWithHelpAttribute(Application.loadedLevelName).Any();
#endif #endif
} }

19
Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunner.cs

@ -8,7 +8,9 @@ using System.Reflection;
using UnityEngine; using UnityEngine;
using UnityTest.IntegrationTestRunner; using UnityTest.IntegrationTestRunner;
using System.IO; using System.IO;
#if UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
#endif
namespace UnityTest namespace UnityTest
{ {
@ -75,7 +77,11 @@ namespace UnityTest
} }
TestComponent.DestroyAllDynamicTests(); TestComponent.DestroyAllDynamicTests();
#if UNITY_5_3_OR_NEWER
var dynamicTestTypes = TestComponent.GetTypesWithHelpAttribute(SceneManager.GetActiveScene().name); var dynamicTestTypes = TestComponent.GetTypesWithHelpAttribute(SceneManager.GetActiveScene().name);
#else
var dynamicTestTypes = TestComponent.GetTypesWithHelpAttribute("");
#endif
foreach (var dynamicTestType in dynamicTestTypes) foreach (var dynamicTestType in dynamicTestTypes)
TestComponent.CreateDynamicTest(dynamicTestType); TestComponent.CreateDynamicTest(dynamicTestType);
@ -310,7 +316,11 @@ namespace UnityTest
string testScene = m_Configurator.GetIntegrationTestScenes(TestSceneNumber); string testScene = m_Configurator.GetIntegrationTestScenes(TestSceneNumber);
if (testScene != null) if (testScene != null)
{
#if UNITY_5_3_OR_NEWER
SceneManager.LoadScene(Path.GetFileNameWithoutExtension(testScene)); SceneManager.LoadScene(Path.GetFileNameWithoutExtension(testScene));
#endif
}
else else
{ {
TestRunnerCallback.AllScenesFinished(); TestRunnerCallback.AllScenesFinished();
@ -373,7 +383,14 @@ namespace UnityTest
currentTest = null; currentTest = null;
if (!testResult.IsSuccess if (!testResult.IsSuccess
&& testResult.Executed && testResult.Executed
&& !testResult.IsIgnored) k_ResultRenderer.AddResults(SceneManager.GetActiveScene().name, testResult); && !testResult.IsIgnored)
{
#if UNITY_5_3_OR_NEWER
k_ResultRenderer.AddResults(SceneManager.GetActiveScene().name, testResult);
#else
k_ResultRenderer.AddResults(Application.loadedLevelName, testResult);
#endif
}
} }
#region Test Runner Helpers #region Test Runner Helpers

Loading…
Cancel
Save