Chris Gregan
9 years ago
86 changed files with 706 additions and 2050 deletions
@ -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 |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 41cffd1c0774e41f1b80ef7fb6f3f158 |
||||
timeCreated: 1438859733 |
||||
licenseType: Free |
||||
NativeFormatImporter: |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -1,5 +1,9 @@
|
||||
fileFormatVersion: 2 |
||||
guid: e22ba039de7077c4aa95758ef723b803 |
||||
folderAsset: yes |
||||
timeCreated: 1445282049 |
||||
licenseType: Store |
||||
DefaultImporter: |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
Binary file not shown.
@ -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: |
Binary file not shown.
@ -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: |
@ -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<Object> 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<FileInfo> DirSearch(DirectoryInfo d, string searchFor) |
||||
{ |
||||
List<FileInfo> 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<Object> AllScenes |
||||
{ |
||||
get |
||||
{ |
||||
// get every single one of the files in the Assets folder. |
||||
List<FileInfo> files = DirSearch(new DirectoryInfo(Application.dataPath), "*.unity"); |
||||
|
||||
// now make them all into Asset references. |
||||
List<Object> assetRefs = new List<Object>(); |
||||
|
||||
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; |
||||
} |
||||
} |
||||
} |
@ -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: |
@ -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 }); |
||||
} |
||||
} |
||||
} |
@ -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<UnitTestResult> m_Results; |
||||
|
||||
public TestRunnerEventListener(string resultFilePath, List<UnitTestResult> 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; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 5401885870ebec84f8e9c6ee18d79695 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -1,5 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: a92d914a774b29f42906161a387d79f7 |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
userData: |
Binary file not shown.
@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 96c89cba541e8fa41acc13fcc8382878 |
||||
MonoAssemblyImporter: |
||||
serializedVersion: 1 |
||||
iconMap: {} |
||||
executionOrder: {} |
||||
userData: |
Binary file not shown.
@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: f8f4181eb51beb043a92433b1c807529 |
||||
MonoAssemblyImporter: |
||||
serializedVersion: 1 |
||||
iconMap: {} |
||||
executionOrder: {} |
||||
userData: |
Binary file not shown.
@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: e8950b8b4aa418a458a503526c8a2f65 |
||||
MonoAssemblyImporter: |
||||
serializedVersion: 1 |
||||
iconMap: {} |
||||
executionOrder: {} |
||||
userData: |
Binary file not shown.
@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: ef8ce5f8e3e580349ac63ac38e87ee2f |
||||
MonoAssemblyImporter: |
||||
serializedVersion: 1 |
||||
iconMap: {} |
||||
executionOrder: {} |
||||
userData: |
Binary file not shown.
@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: f54558e884607254ca91abc9038ac749 |
||||
MonoAssemblyImporter: |
||||
serializedVersion: 1 |
||||
iconMap: {} |
||||
executionOrder: {} |
||||
userData: |
@ -1,4 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: f94e120956782c5498f559719ff38f2a |
||||
DefaultImporter: |
||||
userData: |
@ -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<string> FoldMarkers; |
||||
|
||||
protected static GUIContent s_GUIExpandAll = new GUIContent("Expand all"); |
||||
protected static GUIContent s_GUICollapseAll = new GUIContent("Collapse all"); |
||||
private readonly List<UnitTestRendererLine> m_Children = new List<UnitTestRendererLine>(); |
||||
|
||||
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); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -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<TestLine> |
||||
{ |
||||
public static Func<string, UnitTestResult> GetUnitTestResult; |
||||
|
||||
protected static GUIContent s_GUIOpenInEditor = new GUIContent("Open in editor"); |
||||
private readonly string m_ResultId; |
||||
private readonly IList<string> 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<string>(); |
||||
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); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: cfe0c7d95a79d374e9121633c719241e |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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<UnitTestRendererLine> |
||||
{ |
||||
public static Action<TestFilter> RunTest; |
||||
public static List<UnitTestRendererLine> 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; |
||||
} |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: fddb568bfa3ed03438d5c482ea8c6aea |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -1,5 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 615921b0760fc0c4eaf10b7c88add37b |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
userData: |
@ -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 != "<filename unknown>") |
||||
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<MethodDefinition> 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 }); |
||||
} |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 45a983e950f22034ba987c6db2a8b216 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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); |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 96615b7fd2cb32b4dbea04d84cc3f7fb |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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 |
||||
}; |
||||
} |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 7df86c5f85b0f7d4096d6bc23e9a4e01 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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<UnitTestResult>(); |
||||
var categoryList = new HashSet<string>(); |
||||
|
||||
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<UnitTestResult> results, HashSet<string> 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<UnitTestRendererLine>(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<Assembly>(); |
||||
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<String> 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); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: f313d48559bf30145b88ef7f173685c9 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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<ITestResult>()); |
||||
} |
||||
|
||||
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<ITestResult> m_UpdateCallback; |
||||
|
||||
public TestRunnerEventListener(Action<ITestResult> 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(); |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: fbf567afda42eec43a7dbb052d318076 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -1,62 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using UnityEngine; |
||||
|
||||
namespace UnityTest.UnitTestRunner |
||||
{ |
||||
public class TestRunnerCallbackList : ITestRunnerCallback |
||||
{ |
||||
private readonly List<ITestRunnerCallback> m_CallbackList = new List<ITestRunnerCallback>(); |
||||
|
||||
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); |
||||
} |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: b7a6cf1b9d1273d4187ba9d5bc91fc30 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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<string>().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; |
||||
} |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 39d532431356ff74cb5a51afef8cc308 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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 |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 925cf9f45ea32814da65f61c1ebd7e6f |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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<UnitTestResult> m_ResultList = new List<UnitTestResult>(); |
||||
[SerializeField] private List<string> m_FoldMarkers = new List<string>(); |
||||
[SerializeField] private List<UnitTestRendererLine> m_SelectedLines = new List<UnitTestRendererLine>(); |
||||
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<UnitTestsRunnerSettings>(); |
||||
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<UnitTestResult>(newResults); |
||||
|
||||
m_FilterSettings.UpdateCounters(m_ResultList.Cast<ITestResult>()); |
||||
|
||||
Repaint(); |
||||
} |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: ba152083ecc3cdb4a82881c6a9ae73c1 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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 (); |
||||
} |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 4a24a0b0a24461a4ab99853f8b145e5c |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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; |
||||
} |
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 3ec01611d948e574c99a1bd24650a4a9 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,6 @@
|
||||
%YAML 1.1 |
||||
%TAG !u! tag:unity3d.com,2011: |
||||
--- !u!236 &1 |
||||
ClusterInputManager: |
||||
m_ObjectHideFlags: 0 |
||||
m_Inputs: [] |
@ -1,2 +1,2 @@
|
||||
m_EditorVersion: 5.2.1f1 |
||||
m_EditorVersion: 5.3.0f4 |
||||
m_StandardAssetsVersion: 0 |
||||
|
@ -1,10 +0,0 @@
|
||||
%YAML 1.1 |
||||
%TAG !u! tag:unity3d.com,2011: |
||||
--- !u!303 &1 |
||||
UnityAnalyticsManager: |
||||
m_ObjectHideFlags: 0 |
||||
m_Enabled: 0 |
||||
m_InitializeOnStartup: 1 |
||||
m_TestMode: 0 |
||||
m_TestEventUrl: |
||||
m_TestConfigUrl: |
@ -0,0 +1,14 @@
|
||||
%YAML 1.1 |
||||
%TAG !u! tag:unity3d.com,2011: |
||||
--- !u!310 &1 |
||||
UnityConnectSettings: |
||||
m_ObjectHideFlags: 0 |
||||
UnityPurchasingSettings: |
||||
m_Enabled: 0 |
||||
m_TestMode: 0 |
||||
UnityAnalyticsSettings: |
||||
m_Enabled: 0 |
||||
m_InitializeOnStartup: 1 |
||||
m_TestMode: 0 |
||||
m_TestEventUrl: |
||||
m_TestConfigUrl: |
Loading…
Reference in new issue