diff --git a/Assets/UnityTestTools.meta b/Assets/UnityTestTools.meta index a6d0ba47..1db021ff 100644 --- a/Assets/UnityTestTools.meta +++ b/Assets/UnityTestTools.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 guid: 5c8e5d66ff19140a1bf3cfdc3955859c folderAsset: yes -timeCreated: 1438859672 +timeCreated: 1450715827 licenseType: Free DefaultImporter: userData: diff --git a/Assets/UnityTestTools/Assertions/Editor/AssertionComponentEditor.cs b/Assets/UnityTestTools/Assertions/Editor/AssertionComponentEditor.cs index 7ba8f869..c806621c 100644 --- a/Assets/UnityTestTools/Assertions/Editor/AssertionComponentEditor.cs +++ b/Assets/UnityTestTools/Assertions/Editor/AssertionComponentEditor.cs @@ -23,6 +23,8 @@ namespace UnityTest private readonly GUIContent m_GUIRepeatCheckFrameGuiContent = new GUIContent("Repeat check", "Should the check be repeated."); #endregion + private static List allComparersList = null; + public AssertionComponentEditor() { m_ComparerDropDown.convertForButtonLabel = type => type.Name; @@ -176,8 +178,17 @@ namespace UnityTest private bool DrawComparerSelection(AssertionComponent script) { - var types = typeof(ActionBase).Assembly.GetTypes(); - var allComparers = types.Where(type => type.IsSubclassOf(typeof(ActionBase)) && !type.IsAbstract).ToArray(); + if(allComparersList == null) + { + allComparersList = new List(); + var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); + foreach (var assembly in allAssemblies) + { + var types = assembly.GetTypes(); + allComparersList.AddRange(types.Where(type => type.IsSubclassOf(typeof(ActionBase)) && !type.IsAbstract)); + } + } + var allComparers = allComparersList.ToArray(); if (script.Action == null) script.Action = (ActionBase)CreateInstance(allComparers.First()); diff --git a/Assets/UnityTestTools/Common/Settings.meta b/Assets/UnityTestTools/Common/Settings.meta index a208ce0f..ce35e28a 100644 --- a/Assets/UnityTestTools/Common/Settings.meta +++ b/Assets/UnityTestTools/Common/Settings.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 guid: 4f7795beea73b4d50bd536d0012e8e85 folderAsset: yes -timeCreated: 1438859728 +timeCreated: 1450715835 licenseType: Free DefaultImporter: userData: diff --git a/Assets/UnityTestTools/Common/Settings/IntegrationTestsRunnerSettings.asset.meta b/Assets/UnityTestTools/Common/Settings/IntegrationTestsRunnerSettings.asset.meta index 05dee3d0..6c3c4b27 100644 --- a/Assets/UnityTestTools/Common/Settings/IntegrationTestsRunnerSettings.asset.meta +++ b/Assets/UnityTestTools/Common/Settings/IntegrationTestsRunnerSettings.asset.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: ad7c6353939274fc8a5e756095b99a64 -timeCreated: 1438859728 +timeCreated: 1450715835 licenseType: Free NativeFormatImporter: userData: diff --git a/Assets/UnityTestTools/Common/Settings/UnitTestsRunnerSettings.asset b/Assets/UnityTestTools/Common/Settings/UnitTestsRunnerSettings.asset deleted file mode 100644 index 1e00d2e2..00000000 --- a/Assets/UnityTestTools/Common/Settings/UnitTestsRunnerSettings.asset +++ /dev/null @@ -1,17 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 4a24a0b0a24461a4ab99853f8b145e5c, type: 3} - m_Name: UnitTestsRunnerSettings - m_EditorClassIdentifier: - runOnRecompilation: 0 - horizontalSplit: 1 - autoSaveSceneBeforeRun: 0 - runTestOnANewScene: 0 diff --git a/Assets/UnityTestTools/Common/Settings/UnitTestsRunnerSettings.asset.meta b/Assets/UnityTestTools/Common/Settings/UnitTestsRunnerSettings.asset.meta deleted file mode 100644 index 108d02cc..00000000 --- a/Assets/UnityTestTools/Common/Settings/UnitTestsRunnerSettings.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 41cffd1c0774e41f1b80ef7fb6f3f158 -timeCreated: 1438859733 -licenseType: Free -NativeFormatImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs.meta b/Assets/UnityTestTools/IntegrationTestsFramework/Libs.meta similarity index 55% rename from Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs.meta rename to Assets/UnityTestTools/IntegrationTestsFramework/Libs.meta index 96b0d0fb..1b749751 100644 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs.meta +++ b/Assets/UnityTestTools/IntegrationTestsFramework/Libs.meta @@ -1,5 +1,9 @@ fileFormatVersion: 2 guid: e22ba039de7077c4aa95758ef723b803 folderAsset: yes +timeCreated: 1445282049 +licenseType: Store DefaultImporter: userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.Mdb.dll b/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.Mdb.dll new file mode 100644 index 00000000..161d2fdc Binary files /dev/null and b/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.Mdb.dll differ diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.Mdb.dll.meta b/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.Mdb.dll.meta new file mode 100644 index 00000000..4be4950f --- /dev/null +++ b/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.Mdb.dll.meta @@ -0,0 +1,20 @@ +fileFormatVersion: 2 +guid: 713231d47408a06408a45470c967bae8 +timeCreated: 1441797177 +licenseType: Store +PluginImporter: + serializedVersion: 1 + iconMap: {} + executionOrder: {} + isPreloaded: 0 + platformData: + Any: + enabled: 0 + settings: {} + Editor: + enabled: 1 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.dll b/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.dll new file mode 100644 index 00000000..f55f7a5d Binary files /dev/null and b/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.dll differ diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.dll.meta b/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.dll.meta new file mode 100644 index 00000000..1123a8ae --- /dev/null +++ b/Assets/UnityTestTools/IntegrationTestsFramework/Libs/Mono.Cecil.dll.meta @@ -0,0 +1,20 @@ +fileFormatVersion: 2 +guid: 28fc22990733f8f4ea1137f15e363609 +timeCreated: 1441797177 +licenseType: Store +PluginImporter: + serializedVersion: 1 + iconMap: {} + executionOrder: {} + isPreloaded: 0 + platformData: + Any: + enabled: 0 + settings: {} + Editor: + enabled: 1 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/DTOFormatter.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/DTOFormatter.cs index c3f72747..f974b7c1 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/DTOFormatter.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/DTOFormatter.cs @@ -1,6 +1,8 @@ -using UnityEngine; -using System; +using System; using System.IO; +using System.Runtime.Serialization; +using System.Text; +using UnityEngine; namespace UnityTest { @@ -41,7 +43,7 @@ namespace UnityTest public void Transfer(ref string val) { - var bytes = System.Text.Encoding.BigEndianUnicode.GetBytes(val); + var bytes = Encoding.BigEndianUnicode.GetBytes(val); int length = bytes.Length; Transfer(ref length); _stream.Write(bytes, 0, bytes.Length); @@ -75,8 +77,14 @@ namespace UnityTest int length = 0; Transfer (ref length); var bytes = new byte[length]; - _stream.Read(bytes, 0, length); - val = System.Text.Encoding.BigEndianUnicode.GetString(bytes); + int remain = length; + int index = 0; + do { + int bytesRead = _stream.Read(bytes, index, remain); + remain -= bytesRead; + index += bytesRead; + } while (remain > 0); + val = Encoding.BigEndianUnicode.GetString(bytes); } } @@ -88,20 +96,21 @@ namespace UnityTest transfer.Transfer(ref dto.loadedLevel); transfer.Transfer(ref dto.loadedLevelName); - if(dto.messageType == ResultDTO.MessageType.Ping + if(dto.messageType == ResultDTO.MessageType.Ping || dto.messageType == ResultDTO.MessageType.RunStarted || dto.messageType == ResultDTO.MessageType.RunFinished - || dto.messageType == ResultDTO.MessageType.RunInterrupted) + || dto.messageType == ResultDTO.MessageType.RunInterrupted + || dto.messageType == ResultDTO.MessageType.AllScenesFinished) return; transfer.Transfer(ref dto.testName); transfer.Transfer(ref dto.testTimeout); - if(dto.messageType == ResultDTO.MessageType.TestStarted) - return; - - if(transfer is Reader) - dto.testResult = new SerializableTestResult(); + if(dto.messageType == ResultDTO.MessageType.TestStarted) + return; + + if(transfer is Reader) + dto.testResult = new SerializableTestResult(); SerializableTestResult str = (SerializableTestResult)dto.testResult; transfer.Transfer(ref str.resultState); @@ -115,14 +124,14 @@ namespace UnityTest transfer.Transfer(ref str.stackTrace); } - public void Serialize (System.IO.Stream stream, ResultDTO dto) + public void Serialize (Stream stream, ResultDTO dto) { Transfer(dto, new Writer(stream)); } - public object Deserialize (System.IO.Stream stream) + public object Deserialize (Stream stream) { - var result = (ResultDTO)System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(typeof(ResultDTO)); + var result = (ResultDTO)FormatterServices.GetSafeUninitializedObject(typeof(ResultDTO)); Transfer (result, new Reader(stream)); return result; } diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/Batch.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/Batch.cs index aef16a90..14a82c64 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/Batch.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/Batch.cs @@ -10,36 +10,45 @@ using UnityTest.IntegrationTests; namespace UnityTest { public static partial class Batch - { + { + const string k_ResultFilePathParam = "-resultFilePath="; private const string k_TestScenesParam = "-testscenes="; + private const string k_OtherBuildScenesParam = "-includeBuildScenes="; const string k_TargetPlatformParam = "-targetPlatform="; const string k_ResultFileDirParam = "-resultsFileDirectory="; + public static int returnCodeTestsOk = 0; + public static int returnCodeTestsFailed = 2; + public static int returnCodeRunError = 3; + public static void RunIntegrationTests() { var targetPlatform = GetTargetPlatform(); - var sceneList = GetTestScenesList(); - if (sceneList.Count == 0) - sceneList = FindTestScenesInProject(); - RunIntegrationTests(targetPlatform, sceneList); - } + var otherBuildScenes = GetSceneListFromParam (k_OtherBuildScenesParam); + var testScenes = GetSceneListFromParam(k_TestScenesParam); + if (testScenes.Count == 0) + testScenes = FindTestScenesInProject(); + + RunIntegrationTests(targetPlatform, testScenes, otherBuildScenes); + } + public static void RunIntegrationTests(BuildTarget ? targetPlatform) { var sceneList = FindTestScenesInProject(); - RunIntegrationTests(targetPlatform, sceneList); + RunIntegrationTests(targetPlatform, sceneList, new List()); } - public static void RunIntegrationTests(BuildTarget? targetPlatform, List sceneList) + public static void RunIntegrationTests(BuildTarget? targetPlatform, List testScenes, List otherBuildScenes) { if (targetPlatform.HasValue) - BuildAndRun(targetPlatform.Value, sceneList); + BuildAndRun(targetPlatform.Value, testScenes, otherBuildScenes); else - RunInEditor(sceneList); + RunInEditor(testScenes, otherBuildScenes); } - - private static void BuildAndRun(BuildTarget target, List sceneList) + + private static void BuildAndRun(BuildTarget target, List testScenes, List otherBuildScenes) { var resultFilePath = GetParameterArgument(k_ResultFileDirParam); @@ -49,7 +58,8 @@ namespace UnityTest var config = new PlatformRunnerConfiguration { buildTarget = target, - scenes = sceneList.ToArray(), + buildScenes = otherBuildScenes, + testScenes = testScenes, projectName = "IntegrationTests", resultsDir = resultFilePath, sendResultsOverNetwork = InternalEditorUtility.inBatchMode, @@ -67,19 +77,19 @@ namespace UnityTest PlatformRunner.BuildAndRunInPlayer(config); } - private static void RunInEditor(List sceneList) + private static void RunInEditor(List testScenes, List otherBuildScenes) { CheckActiveBuildTarget(); NetworkResultsReceiver.StopReceiver(); - if (sceneList == null || sceneList.Count == 0) + if (testScenes == null || testScenes.Count == 0) { - Debug.Log("No scenes on the list"); + Debug.Log("No test scenes on the list"); EditorApplication.Exit(returnCodeRunError); return; } - EditorBuildSettings.scenes = sceneList.Select(s => new EditorBuildSettingsScene(s, true)).ToArray(); - EditorApplication.OpenScene(sceneList.First()); + EditorBuildSettings.scenes = (testScenes.Concat(otherBuildScenes).ToList()).Select(s => new EditorBuildSettingsScene(s, true)).ToArray(); + EditorApplication.OpenScene(testScenes.First()); GuiHelper.SetConsoleErrorPause(false); var config = new PlatformRunnerConfiguration @@ -87,7 +97,7 @@ namespace UnityTest resultsDir = GetParameterArgument(k_ResultFileDirParam), ipList = TestRunnerConfigurator.GetAvailableNetworkIPs(), port = PlatformRunnerConfiguration.TryToGetFreePort(), - runInEditor = true, + runInEditor = true }; var settings = new PlayerSettingConfigurator(true); @@ -98,6 +108,18 @@ namespace UnityTest EditorApplication.isPlaying = true; } + private static string GetParameterArgument(string parameterName) + { + foreach (var arg in Environment.GetCommandLineArgs()) + { + if (arg.ToLower().StartsWith(parameterName.ToLower())) + { + return arg.Substring(parameterName.Length); + } + } + return null; + } + static void CheckActiveBuildTarget() { var notSupportedPlatforms = new[] { "MetroPlayer", "WebPlayer", "WebPlayerStreamed" }; @@ -139,14 +161,14 @@ namespace UnityTest return Directory.GetFiles("Assets", integrationTestScenePattern, SearchOption.AllDirectories).ToList(); } - private static List GetTestScenesList() + private static List GetSceneListFromParam(string param) { var sceneList = new List(); foreach (var arg in Environment.GetCommandLineArgs()) { - if (arg.ToLower().StartsWith(k_TestScenesParam)) + if (arg.ToLower().StartsWith(param.ToLower())) { - var scenesFromParam = arg.Substring(k_TestScenesParam.Length).Split(','); + var scenesFromParam = arg.Substring(param.Length).Split(','); foreach (var scene in scenesFromParam) { var sceneName = scene; diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/EditorReferencesUtil.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/EditorReferencesUtil.cs new file mode 100644 index 00000000..3d762b80 --- /dev/null +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/EditorReferencesUtil.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using UnityEditor; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace UnityTest +{ + public static class EditorReferencesUtil + { + + public static List FindScenesWhichContainAsset(string file) + { + string assetPath = GetAssetPathFromFileNameAndExtension (file); + Object cur = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)); + return AllScenes.Where(a => ADependsOnB(a, cur)).ToList(); + } + + private static string CleanPathSeparators(string s) + { + const string forwardSlash = "/"; + const string backSlash = "\\"; + return s.Replace(backSlash, forwardSlash); + } + + private static string GetRelativeAssetPathFromFullPath(string fullPath) + { + fullPath = CleanPathSeparators(fullPath); + if (fullPath.Contains(Application.dataPath)) + { + return fullPath.Replace(Application.dataPath, "Assets"); + } + Debug.LogWarning("Path does not point to a location within Assets: " + fullPath); + return null; + } + + private static string GetAssetPathFromFileNameAndExtension(string assetName) + { + string[] assets = AssetDatabase.FindAssets (Path.GetFileNameWithoutExtension (assetName)); + string assetPath = null; + + foreach (string guid in assets) { + string relativePath = AssetDatabase.GUIDToAssetPath (guid); + + if (Path.GetFileName (relativePath) == Path.GetFileName (assetName)) + assetPath = relativePath; + } + + return assetPath; + } + + private static List DirSearch(DirectoryInfo d, string searchFor) + { + List founditems = d.GetFiles(searchFor).ToList(); + + // Add (by recursing) subdirectory items. + DirectoryInfo[] dis = d.GetDirectories(); + foreach (DirectoryInfo di in dis) + founditems.AddRange(DirSearch(di, searchFor)); + + return (founditems); + } + + private static List AllScenes + { + get + { + // get every single one of the files in the Assets folder. + List files = DirSearch(new DirectoryInfo(Application.dataPath), "*.unity"); + + // now make them all into Asset references. + List assetRefs = new List(); + + foreach (FileInfo fi in files) + { + if (fi.Name.StartsWith(".")) + continue; // Unity ignores dotfiles. + assetRefs.Add(AssetDatabase.LoadMainAssetAtPath(GetRelativeAssetPathFromFullPath(fi.FullName))); + } + return assetRefs; + } + } + + private static bool ADependsOnB(Object obj, Object selectedObj) + { + if (selectedObj == null) return false; + + //optionally, exclude self. + if (selectedObj == obj) return false; + + Object[] dependencies = EditorUtility.CollectDependencies(new Object[1] { obj }); + if (dependencies.Length < 2) return false; // if there's only one, it's us. + + foreach (Object dep in dependencies) + if (dep == selectedObj) + return true; + return false; + } + } +} \ No newline at end of file diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/GroupLine.cs.meta b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/EditorReferencesUtil.cs.meta similarity index 52% rename from Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/GroupLine.cs.meta rename to Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/EditorReferencesUtil.cs.meta index 9195f337..78bcfabf 100644 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/GroupLine.cs.meta +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/EditorReferencesUtil.cs.meta @@ -1,8 +1,12 @@ fileFormatVersion: 2 -guid: 4fcef1ec40255f14d827da8b0d742334 +guid: aad501c968b324cf3a8d1c52eb09ca04 +timeCreated: 1437322927 +licenseType: Store MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/GuiHelper.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/GuiHelper.cs new file mode 100644 index 00000000..7c213ba0 --- /dev/null +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/GuiHelper.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text.RegularExpressions; +using Mono.Cecil; +using Mono.Cecil.Cil; +using Mono.Cecil.Mdb; +using Mono.Collections.Generic; +using UnityEditor; +using UnityEditorInternal; +using UnityEngine; + +namespace UnityTest +{ + public static class GuiHelper + { + public static bool GetConsoleErrorPause() + { + Assembly assembly = Assembly.GetAssembly(typeof(SceneView)); + Type type = assembly.GetType("UnityEditorInternal.LogEntries"); + PropertyInfo method = type.GetProperty("consoleFlags"); + var result = (int)method.GetValue(new object(), new object[] { }); + return (result & (1 << 2)) != 0; + } + + public static void SetConsoleErrorPause(bool b) + { + Assembly assembly = Assembly.GetAssembly(typeof(SceneView)); + Type type = assembly.GetType("UnityEditorInternal.LogEntries"); + MethodInfo method = type.GetMethod("SetConsoleFlag"); + method.Invoke(new object(), new object[] { 1 << 2, b }); + } + } +} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/GuiHelper.cs.meta b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/GuiHelper.cs.meta similarity index 100% rename from Assets/UnityTestTools/UnitTesting/Editor/TestRunner/GuiHelper.cs.meta rename to Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/GuiHelper.cs.meta diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/IntegrationTestsRunnerWindow.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/IntegrationTestsRunnerWindow.cs index d2fa3403..961503cf 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/IntegrationTestsRunnerWindow.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/IntegrationTestsRunnerWindow.cs @@ -32,11 +32,11 @@ namespace UnityTest private IntegrationTestRendererBase[] m_TestLines; private string m_CurrectSceneName; private TestFilterSettings m_FilterSettings; - - Vector2 m_resultTextSize; - string m_resultText; - GameObject m_lastSelectedGO; - int m_resultTestMaxLength = 15000; + + Vector2 m_resultTextSize; + string m_resultText; + GameObject m_lastSelectedGO; + int m_resultTestMaxLength = 15000; [SerializeField] private GameObject m_SelectedLine; [SerializeField] private List m_ResultList = new List(); @@ -82,18 +82,18 @@ namespace UnityTest private static void BackgroundSceneChangeWatch() { - if (!s_Instance) return; + if (!s_Instance) return; if (s_Instance.m_CurrectSceneName != null && s_Instance.m_CurrectSceneName == EditorApplication.currentScene) return; if (EditorApplication.isPlayingOrWillChangePlaymode) return; TestComponent.DestroyAllDynamicTests(); s_Instance.m_CurrectSceneName = EditorApplication.currentScene; - s_Instance.m_ResultList.Clear(); + s_Instance.m_ResultList.Clear(); s_Instance.RebuildTestList(); } public void OnEnable() { - titleContent = new GUIContent("Integration Tests"); + titleContent = new GUIContent("Integration Tests"); s_Instance = this; m_Settings = ProjectSettingsBase.Load(); @@ -151,7 +151,7 @@ namespace UnityTest public static TestResult GetResultForTest(TestComponent tc) { - if(!s_Instance) return new TestResult(tc); + if(!s_Instance) return new TestResult(tc); return s_Instance.m_ResultList.FirstOrDefault(r => r.GameObject == tc.gameObject); } @@ -180,9 +180,9 @@ namespace UnityTest private static void SelectInHierarchy(GameObject gameObject) { - if (!s_Instance) return; - if (gameObject == s_Instance.m_SelectedLine && gameObject.activeInHierarchy) return; - if (EditorApplication.isPlayingOrWillChangePlaymode) return; + if (!s_Instance) return; + if (gameObject == s_Instance.m_SelectedLine && gameObject.activeInHierarchy) return; + if (EditorApplication.isPlayingOrWillChangePlaymode) return; if (!gameObject.activeSelf) { selectedInHierarchy = true; @@ -205,17 +205,17 @@ namespace UnityTest return; FocusWindowIfItsOpen(GetType()); - var testComponents = tests.Where(t => t is TestComponent).Cast().ToList(); - var dynaminTests = testComponents.Where(t => t.dynamic).ToList(); - m_DynamicTestsToRun = dynaminTests.Select(c => c.dynamicTypeName).ToList(); - testComponents.RemoveAll(dynaminTests.Contains); + var testComponents = tests.Where(t => t is TestComponent).Cast().ToList(); + var dynaminTests = testComponents.Where(t => t.dynamic).ToList(); + m_DynamicTestsToRun = dynaminTests.Select(c => c.dynamicTypeName).ToList(); + testComponents.RemoveAll(dynaminTests.Contains); - m_TestsToRun = testComponents.Select( tc => tc.gameObject ).ToList(); + m_TestsToRun = testComponents.Select( tc => tc.gameObject ).ToList(); m_ReadyToRun = true; TestComponent.DisableAllTests(); - EditorApplication.isPlaying = true; + EditorApplication.isPlaying = true; } public void Update() @@ -224,17 +224,17 @@ namespace UnityTest { m_ReadyToRun = false; var testRunner = TestRunner.GetTestRunner(); - testRunner.TestRunnerCallback.Add(new RunnerCallback(this)); - var testComponents = m_TestsToRun.Select(go => go.GetComponent()).ToList(); - testRunner.InitRunner(testComponents, m_DynamicTestsToRun); + testRunner.TestRunnerCallback.Add(new RunnerCallback(this)); + var testComponents = m_TestsToRun.Select(go => go.GetComponent()).ToList(); + testRunner.InitRunner(testComponents, m_DynamicTestsToRun); } } private void RebuildTestList() { m_TestLines = null; - if (!TestComponent.AnyTestsOnScene() - && !TestComponent.AnyDynamicTestForCurrentScene()) return; + if (!TestComponent.AnyTestsOnScene() + && !TestComponent.AnyDynamicTestForCurrentScene()) return; if (!EditorApplication.isPlayingOrWillChangePlaymode) { @@ -428,45 +428,45 @@ namespace UnityTest m_TestInfoScroll = EditorGUILayout.BeginScrollView(m_TestInfoScroll, GUILayout.MinHeight(m_HorizontalSplitBarPosition)); if (m_SelectedLine != null) - UpdateResultText(m_SelectedLine); - - EditorGUILayout.SelectableLabel(m_resultText, Styles.info, - GUILayout.ExpandHeight(true), - GUILayout.ExpandWidth(true), - GUILayout.MinWidth(m_resultTextSize.x), - GUILayout.MinHeight(m_resultTextSize.y)); - EditorGUILayout.EndScrollView(); + UpdateResultText(m_SelectedLine); + + EditorGUILayout.SelectableLabel(m_resultText, Styles.info, + GUILayout.ExpandHeight(true), + GUILayout.ExpandWidth(true), + GUILayout.MinWidth(m_resultTextSize.x), + GUILayout.MinHeight(m_resultTextSize.y)); + EditorGUILayout.EndScrollView(); } private void UpdateResultText(GameObject go) { - if(go == m_lastSelectedGO) return; - m_lastSelectedGO = go; + if(go == m_lastSelectedGO) return; + m_lastSelectedGO = go; var result = m_ResultList.Find(r => r.GameObject == go); if (result == null) - { - m_resultText = string.Empty; - m_resultTextSize = Styles.info.CalcSize(new GUIContent(string.Empty)); - return; - } - var sb = new StringBuilder(result.Name.Trim()); - if (!string.IsNullOrEmpty(result.messages)) - { - sb.Append("\n---\n"); - sb.Append(result.messages.Trim()); - } + { + m_resultText = string.Empty; + m_resultTextSize = Styles.info.CalcSize(new GUIContent(string.Empty)); + return; + } + var sb = new StringBuilder(result.Name.Trim()); + if (!string.IsNullOrEmpty(result.messages)) + { + sb.Append("\n---\n"); + sb.Append(result.messages.Trim()); + } if (!string.IsNullOrEmpty(result.stacktrace)) - { - sb.Append("\n---\n"); - sb.Append(result.stacktrace.Trim()); - } - if(sb.Length>m_resultTestMaxLength) - { - sb.Length = m_resultTestMaxLength; - sb.AppendFormat("...\n\n---MESSAGE TRUNCATED AT {0} CHARACTERS---", m_resultTestMaxLength); - } - m_resultText = sb.ToString().Trim(); - m_resultTextSize = Styles.info.CalcSize(new GUIContent(m_resultText)); + { + sb.Append("\n---\n"); + sb.Append(result.stacktrace.Trim()); + } + if(sb.Length>m_resultTestMaxLength) + { + sb.Length = m_resultTestMaxLength; + sb.AppendFormat("...\n\n---MESSAGE TRUNCATED AT {0} CHARACTERS---", m_resultTestMaxLength); + } + m_resultText = sb.ToString().Trim(); + m_resultTextSize = Styles.info.CalcSize(new GUIContent(m_resultText)); } public void OnInspectorUpdate() @@ -522,6 +522,11 @@ namespace UnityTest PlayerSettings.runInBackground = m_RunInBackground; } + public void AllScenesFinished() + { + + } + public void TestStarted(TestResult test) { m_Window.SetCurrentTest(test.TestComponent); @@ -554,19 +559,19 @@ namespace UnityTest private void OnEditorUpdate() { - if(!EditorApplication.isPlaying) - { - TestRunInterrupted(null); - return; - } - - if (m_Window.m_Settings.blockUIWhenRunning - && m_CurrentTest != null - && !EditorApplication.isPaused + if(!EditorApplication.isPlaying) + { + TestRunInterrupted(null); + return; + } + + if (m_Window.m_Settings.blockUIWhenRunning + && m_CurrentTest != null + && !EditorApplication.isPaused && EditorUtility.DisplayCancelableProgressBar("Integration Test Runner", "Running " + m_CurrentTest.Name, (float)m_CurrentTestNumber / m_TestNumber)) - { + { TestRunInterrupted(null); } } diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/NetworkResultsReceiver.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/NetworkResultsReceiver.cs index 99228fe9..f3be3380 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/NetworkResultsReceiver.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/NetworkResultsReceiver.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Sockets; -using System.Runtime.Serialization.Formatters.Binary; using UnityEditor; using UnityEditorInternal; using UnityEngine; @@ -14,7 +13,7 @@ namespace UnityTest [Serializable] public class NetworkResultsReceiver : EditorWindow { - public static NetworkResultsReceiver Instance = null; + public static NetworkResultsReceiver Instance; private string m_StatusLabel; private TcpListener m_Listener; @@ -100,13 +99,12 @@ namespace UnityTest Debug.LogException(e); } } - if (dto.levelCount - dto.loadedLevel == 1) - { - m_Running = false; - m_RunFinished = true; - } break; - case ResultDTO.MessageType.Ping: + case ResultDTO.MessageType.AllScenesFinished: + m_Running = false; + m_RunFinished = true; + break; + case ResultDTO.MessageType.Ping: break; } } @@ -179,11 +177,7 @@ namespace UnityTest public void OnEnable() { minSize = new Vector2(300, 100); - - //Unity 5.0.0 quirk throws an exception on setting the postion when in batch mode - if( !UnityEditorInternal.InternalEditorUtility.inBatchMode ) - position = new Rect(position.xMin, position.yMin, 300, 100); - titleContent = new GUIContent("Test run monitor"); + titleContent = new GUIContent("Test run monitor"); Instance = this; m_StatusLabel = "Initializing..."; if (EditorApplication.isCompiling) return; @@ -192,7 +186,7 @@ namespace UnityTest private void EnableServer() { - if (m_Configuration == null) throw new Exception("No result receiver server configuration."); + if (m_Configuration == null) throw new Exception("No result receiver server configuration."); var ipAddress = IPAddress.Any; if (m_Configuration.ipList != null && m_Configuration.ipList.Count == 1) @@ -200,7 +194,7 @@ namespace UnityTest var ipAddStr = Equals(ipAddress, IPAddress.Any) ? "[All interfaces]" : ipAddress.ToString(); - m_Listener = new TcpListener(ipAddress, m_Configuration.port); + m_Listener = new TcpListener(ipAddress, m_Configuration.port); m_StatusLabel = "Waiting for connection on: " + ipAddStr + ":" + m_Configuration.port; try @@ -241,10 +235,10 @@ namespace UnityTest { var w = (NetworkResultsReceiver)GetWindow(typeof(NetworkResultsReceiver), false); w.SetConfiguration(configuration); - if (!EditorApplication.isCompiling) - { - w.EnableServer(); - } + if (!EditorApplication.isCompiling) + { + w.EnableServer(); + } w.Show(true); } @@ -256,7 +250,12 @@ namespace UnityTest public static void StopReceiver() { if (Instance == null) return; - Instance.Close(); + try{ + Instance.Close(); + }catch(Exception e){ + Debug.LogException(e); + DestroyImmediate(Instance); + } } } } diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunner.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunner.cs index 230a6a1a..2f649b08 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunner.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunner.cs @@ -5,6 +5,7 @@ using System.Net.Sockets; using UnityEditor; using UnityEditorInternal; using UnityEngine; +using System.Linq; namespace UnityTest.IntegrationTests { @@ -61,8 +62,8 @@ namespace UnityTest.IntegrationTests catch (SocketException e) { Debug.LogException(e); - if (InternalEditorUtility.inBatchMode) - EditorApplication.Exit(Batch.returnCodeRunError); + if (InternalEditorUtility.inBatchMode) + EditorApplication.Exit(Batch.returnCodeRunError); } } @@ -73,11 +74,13 @@ namespace UnityTest.IntegrationTests settings.AddConfigurationFile(TestRunnerConfigurator.integrationTestsNetwork, string.Join("\n", configuration.GetConnectionIPs())); + settings.AddConfigurationFile (TestRunnerConfigurator.testScenesToRun, string.Join ("\n", configuration.testScenes.ToArray())); + settings.ChangeSettingsForIntegrationTests(); AssetDatabase.Refresh(); - var result = BuildPipeline.BuildPlayer(configuration.scenes, + var result = BuildPipeline.BuildPlayer(configuration.testScenes.Concat(configuration.buildScenes).ToArray(), configuration.GetTempPath(), configuration.buildTarget, BuildOptions.AutoRunPlayer | BuildOptions.Development); @@ -96,7 +99,7 @@ namespace UnityTest.IntegrationTests if (configuration.sendResultsOverNetwork) NetworkResultsReceiver.StartReceiver(configuration); - else if (InternalEditorUtility.inBatchMode) + else if (InternalEditorUtility.inBatchMode) EditorApplication.Exit(Batch.returnCodeTestsOk); } diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerConfiguration.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerConfiguration.cs index 01d96098..0d67e854 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerConfiguration.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerConfiguration.cs @@ -10,7 +10,8 @@ using UnityEngine; [Serializable] public class PlatformRunnerConfiguration { - public string[] scenes = new string[0]; + public List buildScenes; + public List testScenes; public BuildTarget buildTarget; public bool runInEditor; public string projectName = EditorApplication.currentScene; diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerSettings.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerSettings.cs index bce27d8f..8b54c3a8 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerSettings.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerSettings.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using UnityEngine; namespace UnityTest diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerSettingsWindow.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerSettingsWindow.cs index 708f6ef3..757968ab 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerSettingsWindow.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/PlatformRunner/PlatformRunnerSettingsWindow.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net; using UnityEditor; using UnityEngine; +using Object = UnityEngine.Object; namespace UnityTest.IntegrationTests { @@ -12,48 +13,166 @@ namespace UnityTest.IntegrationTests public class PlatformRunnerSettingsWindow : EditorWindow { private BuildTarget m_BuildTarget; - private readonly List m_SceneList; + + private List m_IntegrationTestScenes; + private List m_OtherScenesToBuild; + private List m_AllScenesInProject; + private Vector2 m_ScrollPosition; private readonly List m_Interfaces = new List(); private readonly List m_SelectedScenes = new List(); + private int m_SelectedInterface; [SerializeField] private bool m_AdvancedNetworkingSettings; private PlatformRunnerSettings m_Settings; - readonly GUIContent m_Label = new GUIContent("Results target directory", "Directory where the results will be saved. If no value is specified, the results will be generated in project's data folder."); - + private string m_SelectedSceneInAll; + private string m_SelectedSceneInTest; + private string m_SelectedSceneInBuild; + readonly GUIContent m_Label = new GUIContent("Results target directory", "Directory where the results will be saved. If no value is specified, the results will be generated in project's data folder."); + public PlatformRunnerSettingsWindow() { - titleContent = new GUIContent("Platform runner"); + if (m_OtherScenesToBuild == null) + m_OtherScenesToBuild = new List (); + + if (m_IntegrationTestScenes == null) + m_IntegrationTestScenes = new List (); + + titleContent = new GUIContent("Platform runner"); m_BuildTarget = PlatformRunner.defaultBuildTarget; position.Set(position.xMin, position.yMin, 200, position.height); - m_SceneList = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.unity", SearchOption.AllDirectories).ToList(); - m_SceneList.Sort(); + m_AllScenesInProject = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.unity", SearchOption.AllDirectories).ToList(); + m_AllScenesInProject.Sort(); var currentScene = (Directory.GetCurrentDirectory() + EditorApplication.currentScene).Replace("\\", "").Replace("/", ""); - var currentScenePath = m_SceneList.Where(s => s.Replace("\\", "").Replace("/", "") == currentScene); + var currentScenePath = m_AllScenesInProject.Where(s => s.Replace("\\", "").Replace("/", "") == currentScene); m_SelectedScenes.AddRange(currentScenePath); m_Interfaces.Add("(Any)"); m_Interfaces.AddRange(TestRunnerConfigurator.GetAvailableNetworkIPs()); m_Interfaces.Add("127.0.0.1"); + + LoadFromPrefereneces (); } public void OnEnable() { m_Settings = ProjectSettingsBase.Load(); + + // If not configured pre populate with all scenes that have test components on game objects + // This needs to be done outsie of constructor + if (m_IntegrationTestScenes.Count == 0) + m_IntegrationTestScenes = GetScenesWithTestComponents (m_AllScenesInProject); } public void OnGUI() { EditorGUILayout.BeginVertical(); + GUIContent label; + + /* We have three lists here, The tests to run, supporting scenes to include in the build and the list of all scenes so users can + * pick the scenes they want to include. The motiviation here is that test scenes may require to additively load other scenes as part of the tests + */ + EditorGUILayout.BeginHorizontal (); + + // Integration Tests To Run + EditorGUILayout.BeginVertical (); + + label = new GUIContent("Tests:", "All Integration Test scenes that you wish to run on the platform"); + EditorGUILayout.LabelField(label, EditorStyles.boldLabel, GUILayout.Height(20f)); + + EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(m_SelectedSceneInTest)); + if (GUILayout.Button("Remove Integration Test")) { + m_IntegrationTestScenes.Remove(m_SelectedSceneInTest); + m_SelectedSceneInTest = ""; + } + EditorGUI.EndDisabledGroup(); + + DrawVerticalSceneList (ref m_IntegrationTestScenes, ref m_SelectedSceneInTest); + EditorGUILayout.EndVertical (); + + // Extra scenes to include in build + EditorGUILayout.BeginVertical (); + label = new GUIContent("Other Scenes in Build:", "If your Integration Tests additivly load any other scenes then you want to include them here so they are part of the build"); + EditorGUILayout.LabelField(label, EditorStyles.boldLabel, GUILayout.Height(20f)); + + + EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(m_SelectedSceneInBuild)); + if (GUILayout.Button("Remove From Build")) { + m_OtherScenesToBuild.Remove(m_SelectedSceneInBuild); + m_SelectedSceneInBuild = ""; + } + EditorGUI.EndDisabledGroup(); + + DrawVerticalSceneList (ref m_OtherScenesToBuild, ref m_SelectedSceneInBuild); + EditorGUILayout.EndVertical (); + + EditorGUILayout.Separator (); + + // All Scenes + EditorGUILayout.BeginVertical (); + label = new GUIContent("Availble Scenes", "These are all the scenes within your project, please select some to run tests"); + EditorGUILayout.LabelField(label, EditorStyles.boldLabel, GUILayout.Height(20f)); + + + EditorGUILayout.BeginHorizontal (); + EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(m_SelectedSceneInAll)); + if (GUILayout.Button("Add As Test")) { + if (!m_IntegrationTestScenes.Contains (m_SelectedSceneInAll) && !m_OtherScenesToBuild.Contains (m_SelectedSceneInAll)) { + m_IntegrationTestScenes.Add(m_SelectedSceneInAll); + } + } + + if (GUILayout.Button("Add to Build")) { + if (!m_IntegrationTestScenes.Contains (m_SelectedSceneInAll) && !m_OtherScenesToBuild.Contains (m_SelectedSceneInAll)) { + m_OtherScenesToBuild.Add(m_SelectedSceneInAll); + } + } + EditorGUI.EndDisabledGroup(); + + EditorGUILayout.EndHorizontal (); + + DrawVerticalSceneList (ref m_AllScenesInProject, ref m_SelectedSceneInAll); + EditorGUILayout.EndVertical (); + + // ButtoNetworkResultsReceiverns to edit scenes in lists + + + EditorGUILayout.EndHorizontal (); + + GUILayout.Space(3); + + // Select target platform + m_BuildTarget = (BuildTarget)EditorGUILayout.EnumPopup("Build tests for", m_BuildTarget); + + if (PlatformRunner.defaultBuildTarget != m_BuildTarget) + { + if (GUILayout.Button("Make default target platform")) + { + PlatformRunner.defaultBuildTarget = m_BuildTarget; + } + } + GUI.enabled = true; + + // Select various Network settings + DrawSetting(); + var build = GUILayout.Button("Build and run tests"); + EditorGUILayout.EndVertical(); + + if (build) + { + BuildAndRun (); + } + } - EditorGUILayout.LabelField("List of scenes to build:", EditorStyles.boldLabel); + private void DrawVerticalSceneList(ref List sourceList, ref string selectString) + { m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition, Styles.testList); EditorGUI.indentLevel++; - foreach (var scenePath in m_SceneList) + foreach (var scenePath in sourceList) { var path = Path.GetFileNameWithoutExtension(scenePath); var guiContent = new GUIContent(path, scenePath); @@ -62,56 +181,32 @@ namespace UnityTest.IntegrationTests { if (Event.current.type == EventType.mouseDown && Event.current.button == 0) { - if (!Event.current.control && !Event.current.command) - m_SelectedScenes.Clear(); - if (!m_SelectedScenes.Contains(scenePath)) - m_SelectedScenes.Add(scenePath); - else - m_SelectedScenes.Remove(scenePath); + selectString = scenePath; Event.current.Use(); } } var style = new GUIStyle(EditorStyles.label); - if (m_SelectedScenes.Contains(scenePath)) + + if (selectString == scenePath) style.normal.textColor = new Color(0.3f, 0.5f, 0.85f); EditorGUI.LabelField(rect, guiContent, style); } EditorGUI.indentLevel--; EditorGUILayout.EndScrollView(); + } - GUILayout.Space(3); - - m_BuildTarget = (BuildTarget)EditorGUILayout.EnumPopup("Build tests for", m_BuildTarget); - - if (PlatformRunner.defaultBuildTarget != m_BuildTarget) - { - if (GUILayout.Button("Make default target platform")) - { - PlatformRunner.defaultBuildTarget = m_BuildTarget; - } + public static List GetScenesWithTestComponents(List allScenes) + { + List results = EditorReferencesUtil.FindScenesWhichContainAsset("TestComponent.cs"); + List integrationTestScenes = new List(); + + foreach (Object obj in results) { + string result = allScenes.FirstOrDefault(s => s.Contains(obj.name)); + if (!string.IsNullOrEmpty(result)) + integrationTestScenes.Add(result); } - DrawSetting(); - var build = GUILayout.Button("Build and run tests"); - EditorGUILayout.EndVertical(); - - if (!build) return; - - var config = new PlatformRunnerConfiguration - { - buildTarget = m_BuildTarget, - scenes = m_SelectedScenes.ToArray(), - projectName = m_SelectedScenes.Count > 1 ? "IntegrationTests" : Path.GetFileNameWithoutExtension(EditorApplication.currentScene), - resultsDir = m_Settings.resultsPath, - sendResultsOverNetwork = m_Settings.sendResultsOverNetwork, - ipList = m_Interfaces.Skip(1).ToList(), - port = m_Settings.port - }; - - if (m_SelectedInterface > 0) - config.ipList = new List {m_Interfaces.ElementAt(m_SelectedInterface)}; - - PlatformRunner.BuildAndRunInPlayer(config); - Close(); + + return integrationTestScenes; } private void DrawSetting() @@ -159,5 +254,62 @@ namespace UnityTest.IntegrationTests m_Settings.Save(); } } + + private void BuildAndRun() + { + SaveToPreferences (); + + var config = new PlatformRunnerConfiguration + { + buildTarget = m_BuildTarget, + buildScenes = m_OtherScenesToBuild, + testScenes = m_IntegrationTestScenes, + projectName = m_IntegrationTestScenes.Count > 1 ? "IntegrationTests" : Path.GetFileNameWithoutExtension(EditorApplication.currentScene), + resultsDir = m_Settings.resultsPath, + sendResultsOverNetwork = m_Settings.sendResultsOverNetwork, + ipList = m_Interfaces.Skip(1).ToList(), + port = m_Settings.port + }; + + if (m_SelectedInterface > 0) + config.ipList = new List {m_Interfaces.ElementAt(m_SelectedInterface)}; + + PlatformRunner.BuildAndRunInPlayer(config); + Close (); + } + + public void OnLostFocus() { + SaveToPreferences (); + } + + public void OnDestroy() { + SaveToPreferences (); + } + + private void SaveToPreferences() + { + EditorPrefs.SetString (Animator.StringToHash (Application.dataPath + "uttTestScenes").ToString (), String.Join (",",m_IntegrationTestScenes.ToArray())); + EditorPrefs.SetString (Animator.StringToHash (Application.dataPath + "uttBuildScenes").ToString (), String.Join (",",m_OtherScenesToBuild.ToArray())); + } + + private void LoadFromPrefereneces() + { + string storedTestScenes = EditorPrefs.GetString (Animator.StringToHash (Application.dataPath + "uttTestScenes").ToString ()); + string storedBuildScenes = EditorPrefs.GetString (Animator.StringToHash (Application.dataPath + "uttBuildScenes").ToString ()); + + List parsedTestScenes = storedTestScenes.Split (',').ToList (); + List parsedBuildScenes = storedBuildScenes.Split (',').ToList (); + + // Sanity check scenes actually exist + foreach (string str in parsedTestScenes) { + if (m_AllScenesInProject.Contains(str)) + m_IntegrationTestScenes.Add(str); + } + + foreach (string str in parsedBuildScenes) { + if (m_AllScenesInProject.Contains(str)) + m_OtherScenesToBuild.Add(str); + } + } } } diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/RenderingOptions.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/Renderer/RenderingOptions.cs similarity index 100% rename from Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/RenderingOptions.cs rename to Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/Renderer/RenderingOptions.cs diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/RenderingOptions.cs.meta b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/Renderer/RenderingOptions.cs.meta similarity index 100% rename from Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/RenderingOptions.cs.meta rename to Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/Renderer/RenderingOptions.cs.meta diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/ITestRunnerCallback.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/ITestRunnerCallback.cs index c9278e3b..c74dab9d 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/ITestRunnerCallback.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/ITestRunnerCallback.cs @@ -8,6 +8,7 @@ namespace UnityTest.IntegrationTestRunner { void RunStarted(string platform, List testsToRun); void RunFinished(List testResults); + void AllScenesFinished(); void TestStarted(TestResult test); void TestFinished(TestResult test); void TestRunInterrupted(List testsNotRun); diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/IntegrationTest.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/IntegrationTest.cs index eaf03e10..de0e6d18 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/IntegrationTest.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/IntegrationTest.cs @@ -53,14 +53,14 @@ public static class IntegrationTest public static void Assert(bool condition, string message) { - if (condition) Pass(); - else Fail(message); + if (!condition) + Fail(message); } public static void Assert(GameObject go, bool condition, string message) { - if (condition) Pass(go); - else Fail(go, message); + if (!condition) + Fail(go, message); } private static void LogResult(string message) diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/NetworkResultSender.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/NetworkResultSender.cs index d7024d91..16145c09 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/NetworkResultSender.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/NetworkResultSender.cs @@ -99,6 +99,11 @@ namespace UnityTest SendDTO(ResultDTO.CreateTestFinished(test)); } + public void AllScenesFinished() + { + SendDTO (ResultDTO.CreateAllScenesFinished ()); + } + public void TestRunInterrupted(List testsNotRun) { RunFinished(new List()); diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/ResultDTO.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/ResultDTO.cs index 8922b2e2..40224e4b 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/ResultDTO.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/ResultDTO.cs @@ -30,7 +30,8 @@ namespace UnityTest RunFinished, TestStarted, TestFinished, - RunInterrupted + RunInterrupted, + AllScenesFinished } public static ResultDTO CreatePing() @@ -67,6 +68,12 @@ namespace UnityTest return dto; } + public static ResultDTO CreateAllScenesFinished() + { + var dto = new ResultDTO(MessageType.AllScenesFinished); + return dto; + } + private static ITestResult GetSerializableTestResult(TestResult test) { var str = new SerializableTestResult(); diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunner.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunner.cs index be7a2f47..aed12485 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunner.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunner.cs @@ -7,12 +7,14 @@ using System.Linq; using System.Reflection; using UnityEngine; using UnityTest.IntegrationTestRunner; +using System.IO; namespace UnityTest { [Serializable] public class TestRunner : MonoBehaviour { + static private int TestSceneNumber = 0; static private readonly TestResultRenderer k_ResultRenderer = new TestResultRenderer(); public TestComponent currentTest; @@ -222,15 +224,15 @@ namespace UnityTest { if (m_TestState == TestState.Running) { - if(currentTest.ShouldSucceedOnAssertions()) - { - var assertionsToCheck = currentTest.gameObject.GetComponentsInChildren().Where(a => a.enabled).ToArray(); - if (assertionsToCheck.Any () && assertionsToCheck.All(a => a.checksPerformed > 0)) - { - IntegrationTest.Pass(currentTest.gameObject); - m_TestState = TestState.Success; - } - } + if(currentTest.ShouldSucceedOnAssertions()) + { + var assertionsToCheck = currentTest.gameObject.GetComponentsInChildren().Where(a => a.enabled).ToArray(); + if (assertionsToCheck.Any () && assertionsToCheck.All(a => a.checksPerformed > 0)) + { + IntegrationTest.Pass(currentTest.gameObject); + m_TestState = TestState.Success; + } + } if (currentTest != null && Time.time > m_StartTime + currentTest.GetTimeout()) { m_TestState = TestState.Timeout; @@ -302,10 +304,15 @@ namespace UnityTest { if (isInitializedByRunner) return; - if (Application.loadedLevel < Application.levelCount - 1) - Application.LoadLevel(Application.loadedLevel + 1); + + TestSceneNumber += 1; + string testScene = m_Configurator.GetIntegrationTestScenes (TestSceneNumber); + + if (testScene != null) + Application.LoadLevel(Path.GetFileNameWithoutExtension(testScene)); else { + TestRunnerCallback.AllScenesFinished(); k_ResultRenderer.ShowResults(); if (m_Configurator.isBatchRun && m_Configurator.sendResultsOverNetwork) Application.Quit(); diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunnerCallbackList.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunnerCallbackList.cs index d45f3983..91830d2a 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunnerCallbackList.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunnerCallbackList.cs @@ -34,6 +34,14 @@ namespace UnityTest.IntegrationTestRunner } } + public void AllScenesFinished() + { + foreach (var unitTestRunnerCallback in m_CallbackList) + { + unitTestRunnerCallback.AllScenesFinished(); + } + } + public void TestStarted(TestResult test) { foreach (var unitTestRunnerCallback in m_CallbackList) diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunnerConfigurator.cs b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunnerConfigurator.cs index 12041215..51462fa5 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunnerConfigurator.cs +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/TestRunnerConfigurator.cs @@ -24,6 +24,7 @@ namespace UnityTest { public static string integrationTestsNetwork = "networkconfig.txt"; public static string batchRunFileMarker = "batchrun.txt"; + public static string testScenesToRun = "testscenes.txt"; public bool isBatchRun { get; private set; } @@ -39,6 +40,26 @@ namespace UnityTest CheckForSendingResultsOverNetwork(); } + public string GetIntegrationTestScenes(int testSceneNum) + { + string text; + if (Application.isEditor) + text = GetTextFromTempFile(testScenesToRun); + else + text = GetTextFromTextAsset(testScenesToRun); + + List sceneList = new List(); + foreach (var line in text.Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries)) + { + sceneList.Add(line.ToString()); + } + + if (testSceneNum < sceneList.Count) + return sceneList.ElementAt(testSceneNum); + else + return null; + } + private void CheckForSendingResultsOverNetwork() { #if UTT_SOCKETS_SUPPORTED @@ -107,7 +128,7 @@ namespace UnityTest return new List{IPAddress.Loopback.ToString()}; var ipList = new List(); - var allIpsList = new List(); + var allIpsList = new List(); foreach (var netInterface in NetworkInterface.GetAllNetworkInterfaces()) { @@ -115,17 +136,17 @@ namespace UnityTest netInterface.NetworkInterfaceType != NetworkInterfaceType.Ethernet) continue; - var ipAdresses = netInterface.GetIPProperties().UnicastAddresses - .Where(a => a.Address.AddressFamily == AddressFamily.InterNetwork); - allIpsList.AddRange(ipAdresses); + var ipAdresses = netInterface.GetIPProperties().UnicastAddresses + .Where(a => a.Address.AddressFamily == AddressFamily.InterNetwork); + allIpsList.AddRange(ipAdresses); if (netInterface.OperationalStatus != OperationalStatus.Up) continue; - ipList.AddRange(ipAdresses); + ipList.AddRange(ipAdresses); } - //On Mac 10.10 all interfaces return OperationalStatus.Unknown, thus this workaround - if(!ipList.Any()) return allIpsList.Select(i => i.Address.ToString()).ToList(); + //On Mac 10.10 all interfaces return OperationalStatus.Unknown, thus this workaround + if(!ipList.Any()) return allIpsList.Select(i => i.Address.ToString()).ToList(); // sort ip list by their masks to predict which ip belongs to lan network ipList.Sort((ip1, ip2) => diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeCollisionFailure.prefab b/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeCollisionFailure.prefab index fac4d3d1..c1a23a92 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeCollisionFailure.prefab +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeCollisionFailure.prefab @@ -26,7 +26,7 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 100000} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -5.17369938, y: 3.99781466, z: -16.2489204} + m_LocalPosition: {x: -5.1736994, y: 3.9978147, z: -16.24892} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -49,8 +49,10 @@ MeshRenderer: m_ProbeAnchor: {fileID: 0} m_ScaleInLightmap: 1 m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 - m_AutoUVMaxDistance: .5 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeCollisionSuccess.prefab b/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeCollisionSuccess.prefab index 3c867741..6fecda2b 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeCollisionSuccess.prefab +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeCollisionSuccess.prefab @@ -26,7 +26,7 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 100000} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -5.17369938, y: 3.99781466, z: -16.2489204} + m_LocalPosition: {x: -5.1736994, y: 3.9978147, z: -16.24892} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -49,8 +49,10 @@ MeshRenderer: m_ProbeAnchor: {fileID: 0} m_ScaleInLightmap: 1 m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 - m_AutoUVMaxDistance: .5 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeTriggerFailure.prefab b/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeTriggerFailure.prefab index f531ea79..a8289830 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeTriggerFailure.prefab +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeTriggerFailure.prefab @@ -49,8 +49,10 @@ MeshRenderer: m_ProbeAnchor: {fileID: 0} m_ScaleInLightmap: 1 m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 - m_AutoUVMaxDistance: .5 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 diff --git a/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeTriggerSuccess.prefab b/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeTriggerSuccess.prefab index 7bc6c481..cc6f8965 100644 --- a/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeTriggerSuccess.prefab +++ b/Assets/UnityTestTools/IntegrationTestsFramework/TestingAssets/CubeTriggerSuccess.prefab @@ -49,8 +49,10 @@ MeshRenderer: m_ProbeAnchor: {fileID: 0} m_ScaleInLightmap: 1 m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 - m_AutoUVMaxDistance: .5 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 diff --git a/Assets/UnityTestTools/UnitTesting/Editor/Batch.cs b/Assets/UnityTestTools/UnitTesting/Editor/Batch.cs deleted file mode 100644 index 0235e891..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/Batch.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using UnityEditor; -using UnityEngine; -using UnityTest.UnitTestRunner; - -namespace UnityTest -{ - public static partial class Batch - { - const string k_ResultFilePathParam = "-resultFilePath="; - const string k_TestFilterParam = "-filter="; - const string k_CategoryParam = "-categories="; - const string k_DefaultResultFileName = "UnitTestResults.xml"; - - public static int returnCodeTestsOk = 0; - public static int returnCodeTestsFailed = 2; - public static int returnCodeRunError = 3; - - public static void RunUnitTests() - { - PlayerSettings.useMacAppStoreValidation = false; - var filter = GetTestFilter(); - var resultFilePath = GetParameterArgument(k_ResultFilePathParam) ?? Directory.GetCurrentDirectory(); - if (Directory.Exists(resultFilePath)) - resultFilePath = Path.Combine(resultFilePath, k_DefaultResultFileName); - EditorApplication.NewScene(); - var engine = new NUnitTestEngine(); - UnitTestResult[] results; - string[] categories; - engine.GetTests(out results, out categories); - engine.RunTests(filter, new TestRunnerEventListener(resultFilePath, results.ToList())); - } - - private static TestFilter GetTestFilter() - { - var testFilterArg = GetParameterArgumentArray(k_TestFilterParam); - var testCategoryArg = GetParameterArgumentArray(k_CategoryParam); - var filter = new TestFilter - { - names = testFilterArg, - categories = testCategoryArg - }; - return filter; - } - - private static string[] GetParameterArgumentArray(string parameterName) - { - var arg = GetParameterArgument(parameterName); - if (string.IsNullOrEmpty(arg)) return null; - return arg.Split(',').Select(s => s.Trim()).ToArray(); - } - - private static string GetParameterArgument(string parameterName) - { - foreach (var arg in Environment.GetCommandLineArgs()) - { - if (arg.ToLower().StartsWith(parameterName.ToLower())) - { - return arg.Substring(parameterName.Length); - } - } - return null; - } - - private class TestRunnerEventListener : ITestRunnerCallback - { - private readonly string m_ResultFilePath; - private readonly List m_Results; - - public TestRunnerEventListener(string resultFilePath, List resultList) - { - m_ResultFilePath = resultFilePath; - m_Results = resultList; - } - - public void TestFinished(ITestResult test) - { - m_Results.Single(r => r.Id == test.Id).Update(test, false); - } - - public void RunFinished() - { - var resultDestiantion = Application.dataPath; - if (!string.IsNullOrEmpty(m_ResultFilePath)) - resultDestiantion = m_ResultFilePath; - var fileName = Path.GetFileName(resultDestiantion); - if (!string.IsNullOrEmpty(fileName)) - resultDestiantion = resultDestiantion.Substring(0, resultDestiantion.Length - fileName.Length); - else - fileName = "UnitTestResults.xml"; -#if !UNITY_METRO - var resultWriter = new XmlResultWriter("Unit Tests", "Editor", m_Results.ToArray()); - resultWriter.WriteToFile(resultDestiantion, fileName); -#endif - var executed = m_Results.Where(result => result.Executed); - if (!executed.Any()) - { - EditorApplication.Exit(returnCodeRunError); - return; - } - var failed = executed.Where(result => !result.IsSuccess); - EditorApplication.Exit(failed.Any() ? returnCodeTestsFailed : returnCodeTestsOk); - } - - public void TestStarted(string fullName) - { - } - - public void RunStarted(string suiteName, int testCount) - { - } - - public void RunFinishedException(Exception exception) - { - EditorApplication.Exit(returnCodeRunError); - throw exception; - } - } - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/Batch.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/Batch.cs.meta deleted file mode 100644 index 4595868f..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/Batch.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5401885870ebec84f8e9c6ee18d79695 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit.meta b/Assets/UnityTestTools/UnitTesting/Editor/NUnit.meta deleted file mode 100644 index a94ee3ea..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit.meta +++ /dev/null @@ -1,5 +0,0 @@ -fileFormatVersion: 2 -guid: a92d914a774b29f42906161a387d79f7 -folderAsset: yes -DefaultImporter: - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.Mdb.dll b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.Mdb.dll deleted file mode 100644 index 2ddd9768..00000000 Binary files a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.Mdb.dll and /dev/null differ diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.Mdb.dll.meta b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.Mdb.dll.meta deleted file mode 100644 index 36a8c4fc..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.Mdb.dll.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 96c89cba541e8fa41acc13fcc8382878 -MonoAssemblyImporter: - serializedVersion: 1 - iconMap: {} - executionOrder: {} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.dll b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.dll deleted file mode 100644 index 5e59e646..00000000 Binary files a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.dll and /dev/null differ diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.dll.meta b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.dll.meta deleted file mode 100644 index 242413a9..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.dll.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: f8f4181eb51beb043a92433b1c807529 -MonoAssemblyImporter: - serializedVersion: 1 - iconMap: {} - executionOrder: {} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.dll b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.dll deleted file mode 100644 index 46832d4e..00000000 Binary files a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.dll and /dev/null differ diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.dll.meta b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.dll.meta deleted file mode 100644 index 75176314..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.dll.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: e8950b8b4aa418a458a503526c8a2f65 -MonoAssemblyImporter: - serializedVersion: 1 - iconMap: {} - executionOrder: {} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.interfaces.dll b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.interfaces.dll deleted file mode 100644 index 1f2e48a6..00000000 Binary files a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.interfaces.dll and /dev/null differ diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.interfaces.dll.meta b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.interfaces.dll.meta deleted file mode 100644 index b68531c9..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.interfaces.dll.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: ef8ce5f8e3e580349ac63ac38e87ee2f -MonoAssemblyImporter: - serializedVersion: 1 - iconMap: {} - executionOrder: {} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.framework.dll b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.framework.dll deleted file mode 100644 index a50e5313..00000000 Binary files a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.framework.dll and /dev/null differ diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.framework.dll.meta b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.framework.dll.meta deleted file mode 100644 index dad72f0b..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.framework.dll.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: f54558e884607254ca91abc9038ac749 -MonoAssemblyImporter: - serializedVersion: 1 - iconMap: {} - executionOrder: {} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer.meta b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer.meta deleted file mode 100644 index 4ad9a615..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer.meta +++ /dev/null @@ -1,4 +0,0 @@ -fileFormatVersion: 2 -guid: f94e120956782c5498f559719ff38f2a -DefaultImporter: - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/GroupLine.cs b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/GroupLine.cs deleted file mode 100644 index 058e0352..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/GroupLine.cs +++ /dev/null @@ -1,156 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NUnit.Core; -using UnityEditor; -using UnityEngine; -using Event = UnityEngine.Event; - -namespace UnityTest -{ - public class GroupLine : UnitTestRendererLine - { - public static List FoldMarkers; - - protected static GUIContent s_GUIExpandAll = new GUIContent("Expand all"); - protected static GUIContent s_GUICollapseAll = new GUIContent("Collapse all"); - private readonly List m_Children = new List(); - - public GroupLine(TestSuite suite) - : base(suite) - { - if (suite is NamespaceSuite) m_RenderedName = m_FullName; - } - - private bool Folded - { - get { return FoldMarkers.Contains(m_FullName); } - - set - { - if (value) - FoldMarkers.Add(m_FullName); - else - FoldMarkers.RemoveAll(s => s == m_FullName); - } - } - - public void AddChildren(UnitTestRendererLine[] children) - { - m_Children.AddRange(children); - } - - protected internal override void Render(int indend, RenderingOptions options) - { - if (!AnyVisibleChildren(options)) return; - base.Render(indend, options); - if (!Folded) - foreach (var child in m_Children) - child.Render(indend + 1, options); - } - - private bool AnyVisibleChildren(RenderingOptions options) - { - return m_Children.Any(l => l.IsVisible(options)); - } - - protected internal override bool IsVisible(RenderingOptions options) - { - return AnyVisibleChildren(options); - } - - protected override void DrawLine(bool isSelected, RenderingOptions options) - { - var resultIcon = GetResult().HasValue ? GuiHelper.GetIconForResult(GetResult().Value) : Icons.UnknownImg; - - var guiContent = new GUIContent(m_RenderedName, resultIcon, m_FullName); - - var rect = GUILayoutUtility.GetRect(guiContent, Styles.foldout, GUILayout.MaxHeight(16)); - - OnLeftMouseButtonClick(rect); - OnContextClick(rect); - - EditorGUI.BeginChangeCheck(); - var expanded = !EditorGUI.Foldout(rect, !Folded, guiContent, false, isSelected ? Styles.selectedFoldout : Styles.foldout); - if (EditorGUI.EndChangeCheck()) Folded = expanded; - } - - protected internal override TestResultState ? GetResult() - { - TestResultState? tempResult = null; - - foreach (var child in m_Children) - { - var childResultState = child.GetResult(); - - if (childResultState == TestResultState.Failure || childResultState == TestResultState.Error) - { - tempResult = TestResultState.Failure; - break; - } - if (childResultState == TestResultState.Success) - tempResult = TestResultState.Success; - else if (childResultState == TestResultState.Ignored) - tempResult = TestResultState.Ignored; - } - if (tempResult.HasValue) return tempResult.Value; - - return null; - } - - private void OnLeftMouseButtonClick(Rect rect) - { - if (rect.Contains(Event.current.mousePosition) && Event.current.type == EventType.mouseDown && Event.current.button == 0) - { - OnSelect(); - } - } - - private void OnContextClick(Rect rect) - { - if (rect.Contains(Event.current.mousePosition) && Event.current.type == EventType.ContextClick) - { - PrintGroupContextMenu(); - } - } - - private void PrintGroupContextMenu() - { - var multilineSelection = SelectedLines.Count() > 1; - var m = new GenericMenu(); - if (multilineSelection) - { - m.AddItem(s_GUIRunSelected, - false, - data => RunTests(SelectedLines.Select(line => line.m_Test.TestName).ToArray()), - ""); - } - if (!string.IsNullOrEmpty(m_FullName)) - { - m.AddItem(s_GUIRun, - false, - data => RunTests(new[] { m_Test.TestName }), - ""); - } - if (!multilineSelection) - { - m.AddSeparator(""); - - m.AddItem(Folded ? s_GUIExpandAll : s_GUICollapseAll, - false, - data => ExpandOrCollapseAll(Folded), - ""); - } - m.ShowAsContext(); - } - - private void ExpandOrCollapseAll(bool expand) - { - Folded = !expand; - foreach (var child in m_Children) - { - if (child is GroupLine) (child as GroupLine).ExpandOrCollapseAll(expand); - } - } - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/TestLine.cs b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/TestLine.cs deleted file mode 100644 index 352fe8ad..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/TestLine.cs +++ /dev/null @@ -1,182 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NUnit.Core; -using UnityEditor; -using UnityEngine; -using Event = UnityEngine.Event; -using System.Text; - -namespace UnityTest -{ - public class TestLine : UnitTestRendererLine, IComparable - { - public static Func GetUnitTestResult; - - protected static GUIContent s_GUIOpenInEditor = new GUIContent("Open in editor"); - private readonly string m_ResultId; - private readonly IList m_Categories; - private readonly int m_maxLineLenght = 15000; - - private GUIContent m_Content; - - public TestLine(TestMethod test, string resultId) : base(test) - { - m_RenderedName = test.Parent is ParameterizedMethodSuite ? test.TestName.Name : test.MethodName; - - if(m_RenderedName.Length > 100) - m_RenderedName = m_RenderedName.Substring(0, 100); - m_RenderedName = m_RenderedName.Replace("\n", ""); - - m_ResultId = resultId; - var c = new List(); - foreach (string category in test.Categories) - c.Add(category); - foreach (string category in test.Parent.Categories) - c.Add(category); - if (test.Parent is ParameterizedMethodSuite) - foreach (string category in test.Parent.Parent.Categories) - c.Add(category); - m_Categories = c; - m_Content = new GUIContent(m_RenderedName, null, m_FullName); - } - - public UnitTestResult result - { - get { return GetUnitTestResult(m_ResultId); } - } - - public int CompareTo(TestLine other) - { - return result.Id.CompareTo(other.result.Id); - } - - protected override void DrawLine(bool isSelected, RenderingOptions options) - { - if (!IsVisible(options)) return; - - var tempColor = GUI.color; - if (result.Executed && result.Outdated) GUI.color = new Color(1, 1, 1, 0.7f); - - var icon = result.Executed || result.IsIgnored || result.ResultState == TestResultState.NotRunnable - ? GuiHelper.GetIconForResult(result.ResultState) - : Icons.UnknownImg; - if (m_Test.RunState == RunState.Ignored) - icon = GuiHelper.GetIconForResult(TestResultState.Ignored); - - m_Content.image = icon; - - var rect = GUILayoutUtility.GetRect(m_Content, Styles.testName, GUILayout.ExpandWidth(true)); - - OnLeftMouseButtonClick(rect); - OnContextClick(rect); - - if(Event.current.type == EventType.repaint) - Styles.testName.Draw(rect, m_Content, false, false, false, isSelected); - - if (result.Outdated) GUI.color = tempColor; - } - - protected internal override TestResultState ? GetResult() - { - return result.ResultState; - } - - protected internal override bool IsVisible(RenderingOptions options) - { - if (!string.IsNullOrEmpty(options.nameFilter) && !m_FullName.ToLower().Contains(options.nameFilter.ToLower())) - return false; - if (options.categories != null && options.categories.Length > 0 && !options.categories.Any(c => m_Categories.Contains(c))) - return false; - if (!options.showIgnored && (m_Test.RunState == RunState.Ignored || (result.Executed && m_Test.RunState == RunState.Skipped))) - return false; - if (!options.showFailed && result.Executed && (result.IsFailure || result.IsError || result.IsInconclusive)) - return false; - if (!options.showNotRunned && !result.Executed && !result.IsIgnored) - return false; - if (!options.showSucceeded && result.IsSuccess) - return false; - return true; - } - - public override string GetResultText() - { - var tempTest = result; - var sb = new StringBuilder(tempTest.Name); - if (tempTest.Executed) - sb.AppendFormat(" ({0}s)", tempTest.Duration.ToString("##0.###")); - sb.AppendLine(); - - if (!string.IsNullOrEmpty(tempTest.Message)) - { - sb.AppendFormat("---\n{0}\n", tempTest.Message.Trim()); - } - if (!string.IsNullOrEmpty(tempTest.Logs)) - { - sb.AppendFormat("---\n{0}\n", tempTest.Logs.Trim()); - } - if (!tempTest.IsSuccess && !string.IsNullOrEmpty(tempTest.StackTrace)) - { - var stackTrace = StackTraceFilter.Filter(tempTest.StackTrace).Trim(); - sb.AppendFormat("---\n{0}\n", stackTrace); - } - if(sb.Length>m_maxLineLenght) - { - sb.Length = m_maxLineLenght; - sb.AppendFormat("...\n\n---MESSAGE TRUNCATED AT {0} CHARACTERS---", m_maxLineLenght); - } - return sb.ToString().Trim(); - } - - private void OnContextClick(Rect rect) - { - if (rect.Contains(Event.current.mousePosition) && Event.current.type == EventType.ContextClick) - { - Event.current.Use(); - PrintTestContextMenu(); - } - } - - private void PrintTestContextMenu() - { - var m = new GenericMenu(); - var multilineSelection = SelectedLines.Count() > 1; - if (multilineSelection) - { - m.AddItem(s_GUIRunSelected, - false, - data => RunTests(SelectedLines.Select(line => (object)line.m_Test.TestName).ToArray()), - ""); - } - if (!string.IsNullOrEmpty(m_FullName)) - { - m.AddItem(s_GUIRun, - false, - data => RunTests(new[] { (object)m_Test.TestName }), - ""); - } - if (!multilineSelection) - { - m.AddSeparator(""); - - m.AddItem(s_GUIOpenInEditor, - false, - data => GuiHelper.OpenInEditor(result, false), - ""); - } - m.ShowAsContext(); - } - - private void OnLeftMouseButtonClick(Rect rect) - { - if (rect.Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown && Event.current.button == 0) - { - OnSelect(); - if (Event.current.clickCount == 2 && SelectedLines.Count == 1) - { - GuiHelper.OpenInEditor(result, true); - } - } - } - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/TestLine.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/TestLine.cs.meta deleted file mode 100644 index 5f6cf259..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/TestLine.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: cfe0c7d95a79d374e9121633c719241e -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/UnitTestRendererLine.cs b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/UnitTestRendererLine.cs deleted file mode 100644 index 826711d6..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/UnitTestRendererLine.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NUnit.Core; -using UnityEditor; -using UnityEngine; -using Event = UnityEngine.Event; - -namespace UnityTest -{ - public abstract class UnitTestRendererLine : IComparable - { - public static Action RunTest; - public static List SelectedLines; - - protected static bool s_Refresh; - - protected static GUIContent s_GUIRunSelected = new GUIContent("Run Selected"); - protected static GUIContent s_GUIRun = new GUIContent("Run"); - protected static GUIContent s_GUITimeoutIcon = new GUIContent(Icons.StopwatchImg, "Timeout"); - - protected string m_UniqueId; - protected internal string m_FullName; - protected string m_RenderedName; - protected internal Test m_Test; - - protected UnitTestRendererLine(Test test) - { - m_FullName = test.TestName.FullName; - m_RenderedName = test.TestName.Name; - m_UniqueId = test.TestName.UniqueName; - - m_Test = test; - } - - public int CompareTo(UnitTestRendererLine other) - { - return m_UniqueId.CompareTo(other.m_UniqueId); - } - - public bool Render(RenderingOptions options) - { - s_Refresh = false; - EditorGUIUtility.SetIconSize(new Vector2(15, 15)); - Render(0, options); - EditorGUIUtility.SetIconSize(Vector2.zero); - return s_Refresh; - } - - protected internal virtual void Render(int indend, RenderingOptions options) - { - EditorGUILayout.BeginHorizontal(); - GUILayout.Space(indend * 10); - DrawLine(SelectedLines.Contains(this), options); - EditorGUILayout.EndHorizontal(); - } - - protected void OnSelect() - { - if (!Event.current.control && !Event.current.command) - { - SelectedLines.Clear(); - GUIUtility.keyboardControl = 0; - } - if ((Event.current.control || Event.current.command) && SelectedLines.Contains(this)) - SelectedLines.Remove(this); - else - SelectedLines.Add(this); - s_Refresh = true; - } - - protected abstract void DrawLine(bool isSelected, RenderingOptions options); - protected internal abstract TestResultState ? GetResult(); - protected internal abstract bool IsVisible(RenderingOptions options); - - public void RunTests(object[] testObjectsList) - { - RunTest(new TestFilter { objects = testObjectsList }); - } - - public void RunTests(string[] testList) - { - RunTest(new TestFilter {names = testList}); - } - - public void RunSelectedTests() - { - RunTest(new TestFilter { objects = SelectedLines.Select(line => line.m_Test.TestName).ToArray() }); - } - - public bool IsAnySelected - { - get - { - return SelectedLines.Count > 0; - } - } - - public virtual string GetResultText() - { - return m_RenderedName; - } - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/UnitTestRendererLine.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/UnitTestRendererLine.cs.meta deleted file mode 100644 index 6c73d201..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Renderer/UnitTestRendererLine.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: fddb568bfa3ed03438d5c482ea8c6aea -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner.meta b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner.meta deleted file mode 100644 index a253f990..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner.meta +++ /dev/null @@ -1,5 +0,0 @@ -fileFormatVersion: 2 -guid: 615921b0760fc0c4eaf10b7c88add37b -folderAsset: yes -DefaultImporter: - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/GuiHelper.cs b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/GuiHelper.cs deleted file mode 100644 index f9c25310..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/GuiHelper.cs +++ /dev/null @@ -1,147 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text.RegularExpressions; -using Mono.Cecil; -using Mono.Cecil.Cil; -using Mono.Cecil.Mdb; -using Mono.Collections.Generic; -using UnityEditor; -using UnityEditorInternal; -using UnityEngine; - -namespace UnityTest -{ - public static class GuiHelper - { - public static Texture GetIconForResult(TestResultState resultState) - { - switch (resultState) - { - case TestResultState.Success: - return Icons.SuccessImg; - case TestResultState.Failure: - case TestResultState.Error: - return Icons.FailImg; - case TestResultState.Ignored: - case TestResultState.Skipped: - return Icons.IgnoreImg; - case TestResultState.Inconclusive: - case TestResultState.Cancelled: - case TestResultState.NotRunnable: - return Icons.InconclusiveImg; - default: - return Icons.UnknownImg; - } - } - - private static int ExtractSourceFileLine(string stackTrace) - { - int line = 0; - if (!string.IsNullOrEmpty(stackTrace)) - { - var regEx = new Regex(@".* in (?'path'.*):(?'line'\d+)"); - var matches = regEx.Matches(stackTrace); - for (int i = 0; i < matches.Count; i++) - { - line = int.Parse(matches[i].Groups["line"].Value); - if (line != 0) - break; - } - } - return line; - } - - private static string ExtractSourceFilePath(string stackTrace) - { - string path = ""; - if (!string.IsNullOrEmpty(stackTrace)) - { - var regEx = new Regex(@".* in (?'path'.*):(?'line'\d+)"); - var matches = regEx.Matches(stackTrace); - for (int i = 0; i < matches.Count; i++) - { - path = matches[i].Groups["path"].Value; - if (path != "") - break; - } - } - return path; - } - - public static void OpenInEditor(UnitTestResult test, bool openError) - { - var sourceFilePath = ExtractSourceFilePath(test.StackTrace); - var sourceFileLine = ExtractSourceFileLine(test.StackTrace); - - if (!openError || sourceFileLine == 0 || string.IsNullOrEmpty(sourceFilePath)) - { - var sp = GetSequencePointOfTest(test); - if (sp != null) - { - sourceFileLine = sp.StartLine; - sourceFilePath = sp.Document.Url; - } - } - - OpenInEditorInternal(sourceFilePath, sourceFileLine); - } - - private static SequencePoint GetSequencePointOfTest(UnitTestResult test) - { - var readerParameters = new ReaderParameters - { - ReadSymbols = true, - SymbolReaderProvider = new MdbReaderProvider(), - ReadingMode = ReadingMode.Immediate - }; - - var assemblyDefinition = AssemblyDefinition.ReadAssembly(test.Test.AssemblyPath, readerParameters); - var classModule = assemblyDefinition.MainModule.Types.Single(t => t.FullName == test.Test.FullClassName); - - Collection methods; - MethodDefinition method = null; - while (classModule.BaseType != null) - { - methods = classModule.Methods; - if (methods.Any(t => t.Name == test.Test.MethodName)) - { - method = classModule.Methods.First(t => t.Name == test.Test.MethodName); - break; - } - classModule = classModule.BaseType as TypeDefinition; - } - if (method != null) - { - var sp = method.Body.Instructions.First(i => i.SequencePoint != null).SequencePoint; - return sp; - } - return null; - } - - private static void OpenInEditorInternal(string filename, int line) - { - string assetPath = filename.Substring(Application.dataPath.Length - "Assets/".Length + 1); - var scriptAsset = AssetDatabase.LoadMainAssetAtPath(assetPath); - AssetDatabase.OpenAsset(scriptAsset, line); - } - - public static bool GetConsoleErrorPause() - { - Assembly assembly = Assembly.GetAssembly(typeof(SceneView)); - Type type = assembly.GetType("UnityEditorInternal.LogEntries"); - PropertyInfo method = type.GetProperty("consoleFlags"); - var result = (int)method.GetValue(new object(), new object[] { }); - return (result & (1 << 2)) != 0; - } - - public static void SetConsoleErrorPause(bool b) - { - Assembly assembly = Assembly.GetAssembly(typeof(SceneView)); - Type type = assembly.GetType("UnityEditorInternal.LogEntries"); - MethodInfo method = type.GetMethod("SetConsoleFlag"); - method.Invoke(new object(), new object[] { 1 << 2, b }); - } - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/ITestRunnerCallback.cs b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/ITestRunnerCallback.cs deleted file mode 100644 index 9f7b0cc8..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/ITestRunnerCallback.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace UnityTest.UnitTestRunner -{ - public interface ITestRunnerCallback - { - void TestStarted(string fullName); - void TestFinished(ITestResult fullName); - void RunStarted(string suiteName, int testCount); - void RunFinished(); - void RunFinishedException(Exception exception); - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/ITestRunnerCallback.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/ITestRunnerCallback.cs.meta deleted file mode 100644 index 9aea576b..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/ITestRunnerCallback.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 45a983e950f22034ba987c6db2a8b216 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/IUnitTestEngine.cs b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/IUnitTestEngine.cs deleted file mode 100644 index 0452ba18..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/IUnitTestEngine.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; -using UnityTest.UnitTestRunner; - -namespace UnityTest -{ - public interface IUnitTestEngine - { - UnitTestRendererLine GetTests(out UnitTestResult[] results, out string[] categories); - void RunTests(TestFilter filter, ITestRunnerCallback testRunnerEventListener); - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/IUnitTestEngine.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/IUnitTestEngine.cs.meta deleted file mode 100644 index 9eba5da9..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/IUnitTestEngine.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 96615b7fd2cb32b4dbea04d84cc3f7fb -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitExtensions.cs b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitExtensions.cs deleted file mode 100644 index abf963b9..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace UnityTest -{ - public static class NUnitExtensions - { - public static UnitTestResult UnitTestResult(this NUnit.Core.TestResult result, string logs) - { - return new UnitTestResult - { - Executed = result.Executed, - ResultState = (TestResultState)result.ResultState, - Message = result.Message, - Logs = logs, - StackTrace = result.StackTrace, - Duration = result.Time, - Test = new UnitTestInfo(result.Test.TestName.TestID.ToString()), - IsIgnored = (result.ResultState == NUnit.Core.ResultState.Ignored) || result.Test.RunState == NUnit.Core.RunState.Ignored - }; - } - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitExtensions.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitExtensions.cs.meta deleted file mode 100644 index 00de7908..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitExtensions.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 7df86c5f85b0f7d4096d6bc23e9a4e01 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitTestEngine.cs b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitTestEngine.cs deleted file mode 100644 index 2ed658e5..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitTestEngine.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using NUnit.Core; -using NUnit.Core.Filters; -using UnityEditor; -using UnityEngine; -using UnityTest.UnitTestRunner; - -namespace UnityTest -{ - public class NUnitTestEngine : IUnitTestEngine - { - static readonly string[] k_WhitelistedAssemblies = - { - "Assembly-CSharp-Editor", - "Assembly-Boo-Editor", - "Assembly-UnityScript-Editor" - }; - private TestSuite m_TestSuite; - - public UnitTestRendererLine GetTests(out UnitTestResult[] results, out string[] categories) - { - if (m_TestSuite == null) - { - var assemblies = GetAssembliesWithTests().Select(a => a.Location).ToList(); - TestSuite suite = PrepareTestSuite(assemblies); - m_TestSuite = suite; - } - - var resultList = new List(); - var categoryList = new HashSet(); - - UnitTestRendererLine lines = null; - if (m_TestSuite != null) - lines = ParseTestList(m_TestSuite, resultList, categoryList).Single(); - results = resultList.ToArray(); - categories = categoryList.ToArray(); - - return lines; - } - - private UnitTestRendererLine[] ParseTestList(Test test, List results, HashSet categories) - { - foreach (string category in test.Categories) - categories.Add(category); - - if (test is TestMethod) - { - var result = new UnitTestResult - { - Test = new UnitTestInfo(test as TestMethod) - }; - - results.Add(result); - return new[] { new TestLine(test as TestMethod, result.Id) }; - } - - GroupLine group = null; - if (test is TestSuite) - group = new GroupLine(test as TestSuite); - - var namespaceList = new List(new[] {group}); - - foreach (Test result in test.Tests) - { - if (result is NamespaceSuite || test is TestAssembly) - namespaceList.AddRange(ParseTestList(result, results, categories)); - else - group.AddChildren(ParseTestList(result, results, categories)); - } - - namespaceList.Sort(); - return namespaceList.ToArray(); - } - - public void RunTests(ITestRunnerCallback testRunnerEventListener) - { - RunTests(TestFilter.Empty, testRunnerEventListener); - } - - public void RunTests(TestFilter filter, ITestRunnerCallback testRunnerEventListener) - { - try - { - if (testRunnerEventListener != null) - testRunnerEventListener.RunStarted(m_TestSuite.TestName.FullName, m_TestSuite.TestCount); - - ExecuteTestSuite(m_TestSuite, testRunnerEventListener, filter); - - if (testRunnerEventListener != null) - testRunnerEventListener.RunFinished(); - } - catch (Exception e) - { - Debug.LogException(e); - if (testRunnerEventListener != null) - testRunnerEventListener.RunFinishedException(e); - } - } - - public static Assembly[] GetAssembliesWithTests() - { - var libs = new List(); - foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) - { - if (assembly.GetReferencedAssemblies().All(a => a.Name != "nunit.framework")) - continue; - if (assembly.Location.Replace('\\', '/').StartsWith(Application.dataPath) - || k_WhitelistedAssemblies.Contains(assembly.GetName().Name)) - libs.Add(assembly); - } - return libs.ToArray(); - } - - private TestSuite PrepareTestSuite(List assemblyList) - { - CoreExtensions.Host.InitializeService(); - var testPackage = new TestPackage(PlayerSettings.productName, assemblyList); - var builder = new TestSuiteBuilder(); - TestExecutionContext.CurrentContext.TestPackage = testPackage; - TestSuite suite = builder.Build(testPackage); - return suite; - } - - private void ExecuteTestSuite(TestSuite suite, ITestRunnerCallback testRunnerEventListener, TestFilter filter) - { - EventListener eventListener; - if (testRunnerEventListener == null) - eventListener = new NullListener(); - else - eventListener = new TestRunnerEventListener(testRunnerEventListener); - - TestExecutionContext.CurrentContext.Out = new EventListenerTextWriter(eventListener, TestOutputType.Out); - TestExecutionContext.CurrentContext.Error = new EventListenerTextWriter(eventListener, TestOutputType.Error); - - suite.Run(eventListener, GetFilter(filter)); - } - - private ITestFilter GetFilter(TestFilter filter) - { - var nUnitFilter = new AndFilter(); - - if (filter.names != null && filter.names.Length > 0) - nUnitFilter.Add(new SimpleNameFilter(filter.names)); - if (filter.categories != null && filter.categories.Length > 0) - nUnitFilter.Add(new CategoryFilter(filter.categories)); - if (filter.objects != null && filter.objects.Length > 0) - nUnitFilter.Add(new OrFilter(filter.objects.Where(o => o is TestName).Select(o => new NameFilter(o as TestName)).ToArray())); - return nUnitFilter; - } - - public class TestRunnerEventListener : EventListener - { - private readonly ITestRunnerCallback m_TestRunnerEventListener; - private StringBuilder m_testLog; - - public TestRunnerEventListener(ITestRunnerCallback testRunnerEventListener) - { - m_TestRunnerEventListener = testRunnerEventListener; - } - - public void RunStarted(string name, int testCount) - { - m_TestRunnerEventListener.RunStarted(name, testCount); - } - - public void RunFinished(NUnit.Core.TestResult result) - { - m_TestRunnerEventListener.RunFinished(); - } - - public void RunFinished(Exception exception) - { - m_TestRunnerEventListener.RunFinishedException(exception); - } - - public void TestStarted(TestName testName) - { - m_testLog = new StringBuilder(); - m_TestRunnerEventListener.TestStarted(testName.FullName); - } - - public void TestFinished(NUnit.Core.TestResult result) - { - m_TestRunnerEventListener.TestFinished(result.UnitTestResult(m_testLog.ToString())); - m_testLog = null; - } - - public void SuiteStarted(TestName testName) - { - } - - public void SuiteFinished(NUnit.Core.TestResult result) - { - } - - public void UnhandledException(Exception exception) - { - } - - public void TestOutput(TestOutput testOutput) - { - if (m_testLog != null) - m_testLog.AppendLine(testOutput.Text); - } - } - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitTestEngine.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitTestEngine.cs.meta deleted file mode 100644 index 241b6f91..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/NUnitTestEngine.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f313d48559bf30145b88ef7f173685c9 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunner.cs b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunner.cs deleted file mode 100644 index c80c4995..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunner.cs +++ /dev/null @@ -1,150 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using UnityEditor; -using UnityEngine; -using UnityTest.UnitTestRunner; - -namespace UnityTest -{ - public partial class UnitTestView - { - private void UpdateTestInfo(ITestResult result) - { - FindTestResult(result.Id).Update(result, false); - m_FilterSettings.UpdateCounters(m_ResultList.Cast()); - } - - private UnitTestResult FindTestResult(string resultId) - { - var idx = m_ResultList.FindIndex(testResult => testResult.Id == resultId); - if (idx == -1) - { - Debug.LogWarning("Id not found for test: " + resultId); - return null; - } - return m_ResultList.ElementAt(idx); - } - - private void RunTests() - { - var filter = new TestFilter(); - var categories = m_FilterSettings.GetSelectedCategories(); - if (categories != null && categories.Length > 0) - filter.categories = categories; - RunTests(filter); - } - - private void RunTests(TestFilter filter) - { - if (m_Settings.runTestOnANewScene) - { - if (m_Settings.autoSaveSceneBeforeRun) EditorApplication.SaveScene(); - if (!EditorApplication.SaveCurrentSceneIfUserWantsTo()) return; - } - - string currentScene = null; - int undoGroup = -1; - if (m_Settings.runTestOnANewScene) - currentScene = OpenNewScene(); - else - undoGroup = RegisterUndo(); - - StartTestRun(filter, new TestRunnerEventListener(UpdateTestInfo)); - - if (m_Settings.runTestOnANewScene) - LoadPreviousScene(currentScene); - else - PerformUndo(undoGroup); - } - - private string OpenNewScene() - { - var currentScene = EditorApplication.currentScene; - if (m_Settings.runTestOnANewScene) - EditorApplication.NewScene(); - return currentScene; - } - - private void LoadPreviousScene(string currentScene) - { - if (!string.IsNullOrEmpty(currentScene)) - EditorApplication.OpenScene(currentScene); - else - EditorApplication.NewScene(); - - if (Event.current != null) - GUIUtility.ExitGUI(); - } - - public void StartTestRun(TestFilter filter, ITestRunnerCallback eventListener) - { - var callbackList = new TestRunnerCallbackList(); - if (eventListener != null) callbackList.Add(eventListener); - k_TestEngine.RunTests(filter, callbackList); - } - - private static int RegisterUndo() - { - return Undo.GetCurrentGroup(); - } - - private static void PerformUndo(int undoGroup) - { - EditorUtility.DisplayProgressBar("Undo", "Reverting changes to the scene", 0); - var undoStartTime = DateTime.Now; - Undo.RevertAllDownToGroup(undoGroup); - if ((DateTime.Now - undoStartTime).Seconds > 1) - Debug.LogWarning("Undo after unit test run took " + (DateTime.Now - undoStartTime).Seconds + " seconds. Consider running unit tests on a new scene for better performance."); - EditorUtility.ClearProgressBar(); - } - - public class TestRunnerEventListener : ITestRunnerCallback - { - private readonly Action m_UpdateCallback; - - public TestRunnerEventListener(Action updateCallback) - { - m_UpdateCallback = updateCallback; - } - - public void TestStarted(string fullName) - { - EditorUtility.DisplayProgressBar("Unit Tests Runner", fullName, 1); - } - - public void TestFinished(ITestResult result) - { - m_UpdateCallback(result); - } - - public void RunStarted(string suiteName, int testCount) - { - } - - public void RunFinished() - { - EditorUtility.ClearProgressBar(); - } - - public void RunFinishedException(Exception exception) - { - RunFinished(); - } - } - - [MenuItem("Unity Test Tools/Unit Test Runner %#&u")] - public static void ShowWindow() - { - GetWindow(typeof(UnitTestView)).Show(); - } - } - - public class TestFilter - { - public string[] names; - public string[] categories; - public object[] objects; - public static TestFilter Empty = new TestFilter(); - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunner.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunner.cs.meta deleted file mode 100644 index 19127aa4..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunner.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: fbf567afda42eec43a7dbb052d318076 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunnerCallbackList.cs b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunnerCallbackList.cs deleted file mode 100644 index dbe8ad04..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunnerCallbackList.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace UnityTest.UnitTestRunner -{ - public class TestRunnerCallbackList : ITestRunnerCallback - { - private readonly List m_CallbackList = new List(); - - public void TestStarted(string fullName) - { - foreach (var unitTestRunnerCallback in m_CallbackList) - { - unitTestRunnerCallback.TestStarted(fullName); - } - } - - public void TestFinished(ITestResult fullName) - { - foreach (var unitTestRunnerCallback in m_CallbackList) - { - unitTestRunnerCallback.TestFinished(fullName); - } - } - - public void RunStarted(string suiteName, int testCount) - { - foreach (var unitTestRunnerCallback in m_CallbackList) - { - unitTestRunnerCallback.RunStarted(suiteName, - testCount); - } - } - - public void RunFinished() - { - foreach (var unitTestRunnerCallback in m_CallbackList) - { - unitTestRunnerCallback.RunFinished(); - } - } - - public void RunFinishedException(Exception exception) - { - foreach (var unitTestRunnerCallback in m_CallbackList) - { - unitTestRunnerCallback.RunFinishedException(exception); - } - } - - public void Add(ITestRunnerCallback callback) - { - m_CallbackList.Add(callback); - } - - public void Remove(ITestRunnerCallback callback) - { - m_CallbackList.Remove(callback); - } - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunnerCallbackList.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunnerCallbackList.cs.meta deleted file mode 100644 index 83288fbc..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/TestRunnerCallbackList.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: b7a6cf1b9d1273d4187ba9d5bc91fc30 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestInfo.cs b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestInfo.cs deleted file mode 100644 index 5dad7e4b..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestInfo.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text.RegularExpressions; -using NUnit.Core; -using UnityEngine; -using Object = System.Object; - -namespace UnityTest -{ - [Serializable] - public class UnitTestInfo - { - public string ParamName { get; private set; } - public string MethodName { get; private set; } - public string FullMethodName { get; private set; } - public string ClassName { get; private set; } - public string FullClassName { get; private set; } - public string Namespace { get; private set; } - public string FullName { get; private set; } - public string[] Categories { get; private set; } - public string AssemblyPath { get; private set; } - public string Id { get; private set; } - public bool IsIgnored { get; private set; } - - public UnitTestInfo(TestMethod testMethod) - { - if (testMethod == null) - throw new ArgumentException(); - - MethodName = testMethod.MethodName; - FullMethodName = testMethod.Method.ToString(); - ClassName = testMethod.FixtureType.Name; - FullClassName = testMethod.ClassName; - Namespace = testMethod.Method.ReflectedType.Namespace; - FullName = testMethod.TestName.FullName; - ParamName = ExtractMethodCallParametersString(FullName); - Id = testMethod.TestName.TestID.ToString(); - - Categories = testMethod.Categories.Cast().ToArray(); - - AssemblyPath = GetAssemblyPath(testMethod); - - IsIgnored = (testMethod.RunState == RunState.Ignored); - } - - private string GetAssemblyPath(TestMethod testMethod) - { - var parent = testMethod as Test; - var assemblyPath = ""; - while (parent != null) - { - parent = parent.Parent; - if (!(parent is TestAssembly)) continue; - var path = (parent as TestAssembly).TestName.FullName; - if (!File.Exists(path)) continue; - assemblyPath = path; - break; - } - return assemblyPath; - } - - public UnitTestInfo(string id) - { - Id = id; - } - - public override bool Equals(Object obj) - { - if (!(obj is UnitTestInfo)) return false; - - var testInfo = (UnitTestInfo)obj; - return Id == testInfo.Id; - } - - public static bool operator ==(UnitTestInfo a, UnitTestInfo b) - { - if (((object)a == null) || ((object)b == null)) return false; - return a.Id == b.Id; - } - - public static bool operator !=(UnitTestInfo a, UnitTestInfo b) - { - return !(a == b); - } - - public override int GetHashCode() - { - return Id.GetHashCode(); - } - - static string ExtractMethodCallParametersString(string methodFullName) - { - var match = Regex.Match(methodFullName, @"\((.*)\)"); - string result = ""; - if (match.Groups[1].Success) - { - result = match.Groups[1].Captures[0].Value; - } - return result; - } - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestInfo.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestInfo.cs.meta deleted file mode 100644 index 9198408d..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestInfo.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 39d532431356ff74cb5a51afef8cc308 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestResult.cs b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestResult.cs deleted file mode 100644 index 83b5123b..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestResult.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace UnityTest -{ - [Serializable] - public class UnitTestResult : ITestResult - { - public bool Executed { get; set; } - public string Name { get { return Test.MethodName; } } - public string FullName { get { return Test.FullName; } } - public TestResultState ResultState { get; set; } - public UnitTestInfo Test { get; set; } - public string Id { get { return Test.Id; } } - public double Duration { get; set; } - public string Message { get; set; } - public string StackTrace { get; set; } - public bool IsIgnored { get; set; } - - public string Logs { get; set; } - - public bool Outdated { get; set; } - - public void Update(ITestResult source, bool outdated) - { - ResultState = source.ResultState; - Duration = source.Duration; - Message = source.Message; - Logs = source.Logs; - StackTrace = source.StackTrace; - Executed = source.Executed; - IsIgnored = source.IsIgnored || (Test != null && Test.IsIgnored); - Outdated = outdated; - } - - #region Helper methods - - public bool IsFailure - { - get { return ResultState == TestResultState.Failure; } - } - - public bool IsError - { - get { return ResultState == TestResultState.Error; } - } - - public bool IsSuccess - { - get { return ResultState == TestResultState.Success; } - } - - public bool IsInconclusive - { - get { return ResultState == TestResultState.Inconclusive; } - } - - #endregion - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestResult.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestResult.cs.meta deleted file mode 100644 index 03d07e0c..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestResult.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 925cf9f45ea32814da65f61c1ebd7e6f -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestView.cs b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestView.cs deleted file mode 100644 index 62e8c3b5..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestView.cs +++ /dev/null @@ -1,227 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using UnityEditor; -using UnityEngine; -using UnityEditor.Callbacks; - -namespace UnityTest -{ - [Serializable] - public partial class UnitTestView : EditorWindow, IHasCustomMenu - { - private static UnitTestView s_Instance; - private static readonly IUnitTestEngine k_TestEngine = new NUnitTestEngine(); - - [SerializeField] private List m_ResultList = new List(); - [SerializeField] private List m_FoldMarkers = new List(); - [SerializeField] private List m_SelectedLines = new List(); - UnitTestRendererLine m_TestLines; - - private TestFilterSettings m_FilterSettings; - - #region runner steering vars - private Vector2 m_TestListScroll, m_TestInfoScroll; - private float m_HorizontalSplitBarPosition = 200; - private float m_VerticalSplitBarPosition = 300; - #endregion - - private UnitTestsRunnerSettings m_Settings; - - #region GUI Contents - private readonly GUIContent m_GUIRunSelectedTestsIcon = new GUIContent("Run Selected", "Run selected tests"); - private readonly GUIContent m_GUIRunAllTestsIcon = new GUIContent("Run All", "Run all tests"); - private readonly GUIContent m_GUIRerunFailedTestsIcon = new GUIContent("Rerun Failed", "Rerun failed tests"); - private readonly GUIContent m_GUIRunOnRecompile = new GUIContent("Run on recompile", "Run all tests after recompilation"); - private readonly GUIContent m_GUIShowDetailsBelowTests = new GUIContent("Show details below tests", "Show run details below test list"); - private readonly GUIContent m_GUIRunTestsOnNewScene = new GUIContent("Run tests on a new scene", "Run tests on a new scene"); - private readonly GUIContent m_GUIAutoSaveSceneBeforeRun = new GUIContent("Autosave scene", "The runner will automatically save the current scene changes before it starts"); - #endregion - - public UnitTestView() - { - m_ResultList.Clear(); - } - - public void OnEnable() - { - titleContent = new GUIContent("Unit Tests"); - s_Instance = this; - m_Settings = ProjectSettingsBase.Load(); - m_FilterSettings = new TestFilterSettings("UnityTest.UnitTestView"); - RefreshTests(); - } - - [DidReloadScripts] - public static void OnDidReloadScripts() - { - if (s_Instance != null && s_Instance.m_Settings.runOnRecompilation) - { - s_Instance.RunTests(); - s_Instance.Repaint(); - } - } - - public void OnDestroy() - { - s_Instance = null; - } - - public void OnGUI() - { - EditorGUILayout.BeginVertical(); - - EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); - - if (GUILayout.Button(m_GUIRunAllTestsIcon, EditorStyles.toolbarButton)) - { - RunTests(); - GUIUtility.ExitGUI(); - } - EditorGUI.BeginDisabledGroup(!m_TestLines.IsAnySelected); - if (GUILayout.Button(m_GUIRunSelectedTestsIcon, EditorStyles.toolbarButton)) - { - m_TestLines.RunSelectedTests(); - } - EditorGUI.EndDisabledGroup(); - if (GUILayout.Button(m_GUIRerunFailedTestsIcon, EditorStyles.toolbarButton)) - { - m_TestLines.RunTests(m_ResultList.Where(result => result.IsFailure || result.IsError).Select(l => l.FullName).ToArray()); - } - - GUILayout.FlexibleSpace(); - - m_FilterSettings.OnGUI (); - - EditorGUILayout.EndHorizontal(); - - if (m_Settings.horizontalSplit) - EditorGUILayout.BeginVertical(); - else - EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); - - RenderTestList(); - RenderTestInfo(); - - if (m_Settings.horizontalSplit) - EditorGUILayout.EndVertical(); - else - EditorGUILayout.EndHorizontal(); - - EditorGUILayout.EndVertical(); - } - - private void RenderTestList() - { - EditorGUILayout.BeginVertical(Styles.testList); - m_TestListScroll = EditorGUILayout.BeginScrollView(m_TestListScroll, - GUILayout.ExpandWidth(true), - GUILayout.MaxWidth(2000)); - if (m_TestLines != null) - { - if (m_TestLines.Render(m_FilterSettings.BuildRenderingOptions())) Repaint(); - } - EditorGUILayout.EndScrollView(); - EditorGUILayout.EndVertical(); - } - - private void RenderTestInfo() - { - var ctrlId = GUIUtility.GetControlID(FocusType.Passive); - var rect = GUILayoutUtility.GetLastRect(); - if (m_Settings.horizontalSplit) - { - rect.y = rect.height + rect.y - 1; - rect.height = 3; - } - else - { - rect.x = rect.width + rect.x - 1; - rect.width = 3; - } - - EditorGUIUtility.AddCursorRect(rect, m_Settings.horizontalSplit ? MouseCursor.ResizeVertical : MouseCursor.ResizeHorizontal); - var e = Event.current; - switch (e.type) - { - case EventType.MouseDown: - if (GUIUtility.hotControl == 0 && rect.Contains(e.mousePosition)) - GUIUtility.hotControl = ctrlId; - break; - case EventType.MouseDrag: - if (GUIUtility.hotControl == ctrlId) - { - m_HorizontalSplitBarPosition -= e.delta.y; - if (m_HorizontalSplitBarPosition < 20) m_HorizontalSplitBarPosition = 20; - m_VerticalSplitBarPosition -= e.delta.x; - if (m_VerticalSplitBarPosition < 20) m_VerticalSplitBarPosition = 20; - Repaint(); - } - - break; - case EventType.MouseUp: - if (GUIUtility.hotControl == ctrlId) - GUIUtility.hotControl = 0; - break; - } - m_TestInfoScroll = EditorGUILayout.BeginScrollView(m_TestInfoScroll, m_Settings.horizontalSplit - ? GUILayout.MinHeight(m_HorizontalSplitBarPosition) - : GUILayout.Width(m_VerticalSplitBarPosition)); - - var text = ""; - if (m_SelectedLines.Any()) - { - text = m_SelectedLines.First().GetResultText(); - } - - var resultTextSize = Styles.info.CalcSize(new GUIContent(text)); - EditorGUILayout.SelectableLabel(text, Styles.info, - GUILayout.ExpandHeight(true), - GUILayout.ExpandWidth(true), - GUILayout.MinWidth(resultTextSize.x), - GUILayout.MinHeight(resultTextSize.y)); - - EditorGUILayout.EndScrollView(); - } - - private void ToggleRunOnRecompilation() - { - m_Settings.runOnRecompilation = !m_Settings.runOnRecompilation; - } - - public void AddItemsToMenu (GenericMenu menu) - { - menu.AddItem(m_GUIRunOnRecompile, m_Settings.runOnRecompilation, ToggleRunOnRecompilation); - menu.AddItem(m_GUIRunTestsOnNewScene, m_Settings.runTestOnANewScene, m_Settings.ToggleRunTestOnANewScene); - if(!m_Settings.runTestOnANewScene) - menu.AddDisabledItem(m_GUIAutoSaveSceneBeforeRun); - else - menu.AddItem(m_GUIAutoSaveSceneBeforeRun, m_Settings.autoSaveSceneBeforeRun, m_Settings.ToggleAutoSaveSceneBeforeRun); - menu.AddItem(m_GUIShowDetailsBelowTests, m_Settings.horizontalSplit, m_Settings.ToggleHorizontalSplit); - } - - private void RefreshTests() - { - UnitTestResult[] newResults; - m_TestLines = k_TestEngine.GetTests(out newResults, out m_FilterSettings.AvailableCategories); - - foreach (var newResult in newResults) - { - var result = m_ResultList.Where(t => t.Test == newResult.Test && t.FullName == newResult.FullName).ToArray(); - if (result.Count() != 1) continue; - newResult.Update(result.Single(), true); - } - - UnitTestRendererLine.SelectedLines = m_SelectedLines; - UnitTestRendererLine.RunTest = RunTests; - GroupLine.FoldMarkers = m_FoldMarkers; - TestLine.GetUnitTestResult = FindTestResult; - - m_ResultList = new List(newResults); - - m_FilterSettings.UpdateCounters(m_ResultList.Cast()); - - Repaint(); - } - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestView.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestView.cs.meta deleted file mode 100644 index 55bd7001..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/TestRunner/UnitTestView.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ba152083ecc3cdb4a82881c6a9ae73c1 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/UnitTestsRunnerSettings.cs b/Assets/UnityTestTools/UnitTesting/Editor/UnitTestsRunnerSettings.cs deleted file mode 100644 index 1feca66e..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/UnitTestsRunnerSettings.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace UnityTest -{ - - public class UnitTestsRunnerSettings : ProjectSettingsBase - { - public bool runOnRecompilation; - public bool horizontalSplit = true; - public bool autoSaveSceneBeforeRun; - public bool runTestOnANewScene; - - public void ToggleRunTestOnANewScene() { - runTestOnANewScene = !runTestOnANewScene; - Save (); - } - - public void ToggleAutoSaveSceneBeforeRun() { - autoSaveSceneBeforeRun = !autoSaveSceneBeforeRun; - Save (); - } - - public void ToggleHorizontalSplit() { - horizontalSplit = !horizontalSplit; - Save (); - } - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/UnitTestsRunnerSettings.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/UnitTestsRunnerSettings.cs.meta deleted file mode 100644 index 4e53a94d..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/UnitTestsRunnerSettings.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 4a24a0b0a24461a4ab99853f8b145e5c -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/UnitTesting/Editor/UnityUnitTest.cs b/Assets/UnityTestTools/UnitTesting/Editor/UnityUnitTest.cs deleted file mode 100644 index 32751ec0..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/UnityUnitTest.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using NUnit.Framework; -using UnityEditor; -using UnityEngine; - -[TestFixture] -public abstract class UnityUnitTest -{ - public GameObject CreateGameObject() - { - return CreateGameObject(""); - } - - public GameObject CreateGameObject(string name) - { - var go = string.IsNullOrEmpty(name) ? new GameObject() : new GameObject(name); - Undo.RegisterCreatedObjectUndo(go, ""); - return go; - } - - public GameObject CreatePrimitive(PrimitiveType type) - { - var p = GameObject.CreatePrimitive(type); - Undo.RegisterCreatedObjectUndo(p, ""); - return p; - } -} diff --git a/Assets/UnityTestTools/UnitTesting/Editor/UnityUnitTest.cs.meta b/Assets/UnityTestTools/UnitTesting/Editor/UnityUnitTest.cs.meta deleted file mode 100644 index 0185d4b3..00000000 --- a/Assets/UnityTestTools/UnitTesting/Editor/UnityUnitTest.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 3ec01611d948e574c99a1bd24650a4a9 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/UnityTestTools/changelog.txt b/Assets/UnityTestTools/changelog.txt index 6c25e1f2..e80d3d61 100644 --- a/Assets/UnityTestTools/changelog.txt +++ b/Assets/UnityTestTools/changelog.txt @@ -1,3 +1,17 @@ +Version 1.5.7 + +- Updated tools for Unity 5.3 + +Version 1.5.6 + +- Updated Mono.Cecil.dll and Mono.Cecil.Mdb.dll libraries + +Version 1.5.5 + +- Unit Tests Runner rendering improvments +- Platform runner can include auxiliary scenes +- other improvments and bugfixes + Version 1.5.4 - APIs updates