Commit af571a61 authored by BlackAngle233's avatar BlackAngle233
Browse files

212

parent 1d9b5391
fileFormatVersion: 2
guid: fd57cf917f61bbb42b8f030436426ddd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: fd57cf917f61bbb42b8f030436426ddd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 07ea0326ed848fb4489187cb58f96113
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 07ea0326ed848fb4489187cb58f96113
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class RenderingOptions
{
public string nameFilter;
public bool showSucceeded;
public bool showFailed;
public bool showIgnored;
public bool showNotRunned;
public string[] categories;
}
}
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class RenderingOptions
{
public string nameFilter;
public bool showSucceeded;
public bool showFailed;
public bool showIgnored;
public bool showNotRunned;
public string[] categories;
}
}
fileFormatVersion: 2
guid: 87357ff0dec4ef348a295235835c6ee4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 87357ff0dec4ef348a295235835c6ee4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
// ****************************************************************
// Based on nUnit 2.6.2 (http://www.nunit.org/)
// ****************************************************************
using System;
using System.Collections.Generic;
using UnityEngine.TestTools.TestRunner.GUI;
namespace UnityEditor.TestTools.TestRunner.GUI
{
/// <summary>
/// Summary description for ResultSummarizer.
/// </summary>
internal class ResultSummarizer
{
private int m_ErrorCount = -1;
private int m_FailureCount;
private int m_IgnoreCount = -1;
private int m_InconclusiveCount = -1;
private int m_NotRunnable = -1;
private int m_ResultCount;
private int m_SkipCount;
private int m_SuccessCount;
private int m_TestsRun;
private TimeSpan m_Duration = TimeSpan.FromSeconds(0);
public ResultSummarizer(IEnumerable<TestRunnerResult> results)
{
foreach (var result in results)
Summarize(result);
}
public bool success
{
get { return m_FailureCount == 0; }
}
/// <summary>
/// Returns the number of test cases for which results
/// have been summarized. Any tests excluded by use of
/// Category or Explicit attributes are not counted.
/// </summary>
public int ResultCount
{
get { return m_ResultCount; }
}
/// <summary>
/// Returns the number of test cases actually run, which
/// is the same as ResultCount, less any Skipped, Ignored
/// or NonRunnable tests.
/// </summary>
public int TestsRun
{
get { return m_TestsRun; }
}
/// <summary>
/// Returns the number of tests that passed
/// </summary>
public int Passed
{
get { return m_SuccessCount; }
}
/// <summary>
/// Returns the number of test cases that had an error.
/// </summary>
public int errors
{
get { return m_ErrorCount; }
}
/// <summary>
/// Returns the number of test cases that failed.
/// </summary>
public int failures
{
get { return m_FailureCount; }
}
/// <summary>
/// Returns the number of test cases that failed.
/// </summary>
public int inconclusive
{
get { return m_InconclusiveCount; }
}
/// <summary>
/// Returns the number of test cases that were not runnable
/// due to errors in the signature of the class or method.
/// Such tests are also counted as Errors.
/// </summary>
public int notRunnable
{
get { return m_NotRunnable; }
}
/// <summary>
/// Returns the number of test cases that were skipped.
/// </summary>
public int Skipped
{
get { return m_SkipCount; }
}
public int ignored
{
get { return m_IgnoreCount; }
}
public double duration
{
get { return m_Duration.TotalSeconds; }
}
public int testsNotRun
{
get { return m_SkipCount + m_IgnoreCount + m_NotRunnable; }
}
public void Summarize(TestRunnerResult result)
{
m_Duration += TimeSpan.FromSeconds(result.duration);
m_ResultCount++;
if (result.resultStatus != TestRunnerResult.ResultStatus.NotRun)
{
//TODO implement missing features
// if(result.IsIgnored)
// {
// m_IgnoreCount++;
// return;
// }
m_SkipCount++;
return;
}
switch (result.resultStatus)
{
case TestRunnerResult.ResultStatus.Passed:
m_SuccessCount++;
m_TestsRun++;
break;
case TestRunnerResult.ResultStatus.Failed:
m_FailureCount++;
m_TestsRun++;
break;
//TODO implement missing features
// case TestResultState.Error:
// case TestResultState.Cancelled:
// m_ErrorCount++;
// m_TestsRun++;
// break;
// case TestResultState.Inconclusive:
// m_InconclusiveCount++;
// m_TestsRun++;
// break;
// case TestResultState.NotRunnable:
// m_NotRunnable++;
// // errorCount++;
// break;
// case TestResultState.Ignored:
// m_IgnoreCount++;
// break;
default:
m_SkipCount++;
break;
}
}
}
}
// ****************************************************************
// Based on nUnit 2.6.2 (http://www.nunit.org/)
// ****************************************************************
using System;
using System.Collections.Generic;
using UnityEngine.TestTools.TestRunner.GUI;
namespace UnityEditor.TestTools.TestRunner.GUI
{
/// <summary>
/// Summary description for ResultSummarizer.
/// </summary>
internal class ResultSummarizer
{
private int m_ErrorCount = -1;
private int m_FailureCount;
private int m_IgnoreCount = -1;
private int m_InconclusiveCount = -1;
private int m_NotRunnable = -1;
private int m_ResultCount;
private int m_SkipCount;
private int m_SuccessCount;
private int m_TestsRun;
private TimeSpan m_Duration = TimeSpan.FromSeconds(0);
public ResultSummarizer(IEnumerable<TestRunnerResult> results)
{
foreach (var result in results)
Summarize(result);
}
public bool success
{
get { return m_FailureCount == 0; }
}
/// <summary>
/// Returns the number of test cases for which results
/// have been summarized. Any tests excluded by use of
/// Category or Explicit attributes are not counted.
/// </summary>
public int ResultCount
{
get { return m_ResultCount; }
}
/// <summary>
/// Returns the number of test cases actually run, which
/// is the same as ResultCount, less any Skipped, Ignored
/// or NonRunnable tests.
/// </summary>
public int TestsRun
{
get { return m_TestsRun; }
}
/// <summary>
/// Returns the number of tests that passed
/// </summary>
public int Passed
{
get { return m_SuccessCount; }
}
/// <summary>
/// Returns the number of test cases that had an error.
/// </summary>
public int errors
{
get { return m_ErrorCount; }
}
/// <summary>
/// Returns the number of test cases that failed.
/// </summary>
public int failures
{
get { return m_FailureCount; }
}
/// <summary>
/// Returns the number of test cases that failed.
/// </summary>
public int inconclusive
{
get { return m_InconclusiveCount; }
}
/// <summary>
/// Returns the number of test cases that were not runnable
/// due to errors in the signature of the class or method.
/// Such tests are also counted as Errors.
/// </summary>
public int notRunnable
{
get { return m_NotRunnable; }
}
/// <summary>
/// Returns the number of test cases that were skipped.
/// </summary>
public int Skipped
{
get { return m_SkipCount; }
}
public int ignored
{
get { return m_IgnoreCount; }
}
public double duration
{
get { return m_Duration.TotalSeconds; }
}
public int testsNotRun
{
get { return m_SkipCount + m_IgnoreCount + m_NotRunnable; }
}
public void Summarize(TestRunnerResult result)
{
m_Duration += TimeSpan.FromSeconds(result.duration);
m_ResultCount++;
if (result.resultStatus != TestRunnerResult.ResultStatus.NotRun)
{
//TODO implement missing features
// if(result.IsIgnored)
// {
// m_IgnoreCount++;
// return;
// }
m_SkipCount++;
return;
}
switch (result.resultStatus)
{
case TestRunnerResult.ResultStatus.Passed:
m_SuccessCount++;
m_TestsRun++;
break;
case TestRunnerResult.ResultStatus.Failed:
m_FailureCount++;
m_TestsRun++;
break;
//TODO implement missing features
// case TestResultState.Error:
// case TestResultState.Cancelled:
// m_ErrorCount++;
// m_TestsRun++;
// break;
// case TestResultState.Inconclusive:
// m_InconclusiveCount++;
// m_TestsRun++;
// break;
// case TestResultState.NotRunnable:
// m_NotRunnable++;
// // errorCount++;
// break;
// case TestResultState.Ignored:
// m_IgnoreCount++;
// break;
default:
m_SkipCount++;
break;
}
}
}
}
fileFormatVersion: 2
guid: 95a2914724952ef40bb590d0607fc878
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 95a2914724952ef40bb590d0607fc878
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.TestTools.TestRunner.GUI;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class TestFilterSettings
{
public bool showSucceeded;
public bool showFailed;
public bool showIgnored;
public bool showNotRun;
public string filterByName;
public int filterByCategory;
private GUIContent m_SucceededBtn;
private GUIContent m_FailedBtn;
private GUIContent m_IgnoredBtn;
private GUIContent m_NotRunBtn;
public string[] availableCategories;
private readonly string m_PrefsKey;
public TestFilterSettings(string prefsKey)
{
availableCategories = null;
m_PrefsKey = prefsKey;
Load();
UpdateCounters(Enumerable.Empty<TestRunnerResult>());
}
public void Load()
{
showSucceeded = EditorPrefs.GetBool(m_PrefsKey + ".ShowSucceeded", true);
showFailed = EditorPrefs.GetBool(m_PrefsKey + ".ShowFailed", true);
showIgnored = EditorPrefs.GetBool(m_PrefsKey + ".ShowIgnored", true);
showNotRun = EditorPrefs.GetBool(m_PrefsKey + ".ShowNotRun", true);
filterByName = EditorPrefs.GetString(m_PrefsKey + ".FilterByName", string.Empty);
filterByCategory = EditorPrefs.GetInt(m_PrefsKey + ".FilterByCategory", 0);
}
public void Save()
{
EditorPrefs.SetBool(m_PrefsKey + ".ShowSucceeded", showSucceeded);
EditorPrefs.SetBool(m_PrefsKey + ".ShowFailed", showFailed);
EditorPrefs.SetBool(m_PrefsKey + ".ShowIgnored", showIgnored);
EditorPrefs.SetBool(m_PrefsKey + ".ShowNotRun", showNotRun);
EditorPrefs.SetString(m_PrefsKey + ".FilterByName", filterByName);
EditorPrefs.SetInt(m_PrefsKey + ".FilterByCategory", filterByCategory);
}
public void UpdateCounters(IEnumerable<TestRunnerResult> results)
{
var summary = new ResultSummarizer(results);
m_SucceededBtn = new GUIContent(summary.Passed.ToString(), Icons.s_SuccessImg, "Show tests that succeeded");
m_FailedBtn = new GUIContent((summary.errors + summary.failures + summary.inconclusive).ToString(), Icons.s_FailImg, "Show tests that failed");
m_IgnoredBtn = new GUIContent((summary.ignored + summary.notRunnable).ToString(), Icons.s_IgnoreImg, "Show tests that are ignored");
m_NotRunBtn = new GUIContent((summary.testsNotRun - summary.ignored - summary.notRunnable).ToString(), Icons.s_UnknownImg, "Show tests that didn't run");
}
public string[] GetSelectedCategories()
{
if (availableCategories == null)
return new string[0];
return availableCategories.Where((c, i) => (filterByCategory & (1 << i)) != 0).ToArray();
}
public void OnGUI()
{
EditorGUI.BeginChangeCheck();
filterByName = GUILayout.TextField(filterByName, "ToolbarSeachTextField", GUILayout.MinWidth(100), GUILayout.MaxWidth(250), GUILayout.ExpandWidth(true));
if (GUILayout.Button(GUIContent.none, string.IsNullOrEmpty(filterByName) ? "ToolbarSeachCancelButtonEmpty" : "ToolbarSeachCancelButton"))
filterByName = string.Empty;
if (availableCategories != null && availableCategories.Length > 0)
filterByCategory = EditorGUILayout.MaskField(filterByCategory, availableCategories, EditorStyles.toolbarDropDown, GUILayout.MaxWidth(90));
showSucceeded = GUILayout.Toggle(showSucceeded, m_SucceededBtn, EditorStyles.toolbarButton);
showFailed = GUILayout.Toggle(showFailed, m_FailedBtn, EditorStyles.toolbarButton);
showIgnored = GUILayout.Toggle(showIgnored, m_IgnoredBtn, EditorStyles.toolbarButton);
showNotRun = GUILayout.Toggle(showNotRun, m_NotRunBtn, EditorStyles.toolbarButton);
if (EditorGUI.EndChangeCheck())
Save();
}
public RenderingOptions BuildRenderingOptions()
{
var options = new RenderingOptions();
options.showSucceeded = showSucceeded;
options.showFailed = showFailed;
options.showIgnored = showIgnored;
options.showNotRunned = showNotRun;
options.nameFilter = filterByName;
options.categories = GetSelectedCategories();
return options;
}
}
}
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.TestTools.TestRunner.GUI;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class TestFilterSettings
{
public bool showSucceeded;
public bool showFailed;
public bool showIgnored;
public bool showNotRun;
public string filterByName;
public int filterByCategory;
private GUIContent m_SucceededBtn;
private GUIContent m_FailedBtn;
private GUIContent m_IgnoredBtn;
private GUIContent m_NotRunBtn;
public string[] availableCategories;
private readonly string m_PrefsKey;
public TestFilterSettings(string prefsKey)
{
availableCategories = null;
m_PrefsKey = prefsKey;
Load();
UpdateCounters(Enumerable.Empty<TestRunnerResult>());
}
public void Load()
{
showSucceeded = EditorPrefs.GetBool(m_PrefsKey + ".ShowSucceeded", true);
showFailed = EditorPrefs.GetBool(m_PrefsKey + ".ShowFailed", true);
showIgnored = EditorPrefs.GetBool(m_PrefsKey + ".ShowIgnored", true);
showNotRun = EditorPrefs.GetBool(m_PrefsKey + ".ShowNotRun", true);
filterByName = EditorPrefs.GetString(m_PrefsKey + ".FilterByName", string.Empty);
filterByCategory = EditorPrefs.GetInt(m_PrefsKey + ".FilterByCategory", 0);
}
public void Save()
{
EditorPrefs.SetBool(m_PrefsKey + ".ShowSucceeded", showSucceeded);
EditorPrefs.SetBool(m_PrefsKey + ".ShowFailed", showFailed);
EditorPrefs.SetBool(m_PrefsKey + ".ShowIgnored", showIgnored);
EditorPrefs.SetBool(m_PrefsKey + ".ShowNotRun", showNotRun);
EditorPrefs.SetString(m_PrefsKey + ".FilterByName", filterByName);
EditorPrefs.SetInt(m_PrefsKey + ".FilterByCategory", filterByCategory);
}
public void UpdateCounters(IEnumerable<TestRunnerResult> results)
{
var summary = new ResultSummarizer(results);
m_SucceededBtn = new GUIContent(summary.Passed.ToString(), Icons.s_SuccessImg, "Show tests that succeeded");
m_FailedBtn = new GUIContent((summary.errors + summary.failures + summary.inconclusive).ToString(), Icons.s_FailImg, "Show tests that failed");
m_IgnoredBtn = new GUIContent((summary.ignored + summary.notRunnable).ToString(), Icons.s_IgnoreImg, "Show tests that are ignored");
m_NotRunBtn = new GUIContent((summary.testsNotRun - summary.ignored - summary.notRunnable).ToString(), Icons.s_UnknownImg, "Show tests that didn't run");
}
public string[] GetSelectedCategories()
{
if (availableCategories == null)
return new string[0];
return availableCategories.Where((c, i) => (filterByCategory & (1 << i)) != 0).ToArray();
}
public void OnGUI()
{
EditorGUI.BeginChangeCheck();
filterByName = GUILayout.TextField(filterByName, "ToolbarSeachTextField", GUILayout.MinWidth(100), GUILayout.MaxWidth(250), GUILayout.ExpandWidth(true));
if (GUILayout.Button(GUIContent.none, string.IsNullOrEmpty(filterByName) ? "ToolbarSeachCancelButtonEmpty" : "ToolbarSeachCancelButton"))
filterByName = string.Empty;
if (availableCategories != null && availableCategories.Length > 0)
filterByCategory = EditorGUILayout.MaskField(filterByCategory, availableCategories, EditorStyles.toolbarDropDown, GUILayout.MaxWidth(90));
showSucceeded = GUILayout.Toggle(showSucceeded, m_SucceededBtn, EditorStyles.toolbarButton);
showFailed = GUILayout.Toggle(showFailed, m_FailedBtn, EditorStyles.toolbarButton);
showIgnored = GUILayout.Toggle(showIgnored, m_IgnoredBtn, EditorStyles.toolbarButton);
showNotRun = GUILayout.Toggle(showNotRun, m_NotRunBtn, EditorStyles.toolbarButton);
if (EditorGUI.EndChangeCheck())
Save();
}
public RenderingOptions BuildRenderingOptions()
{
var options = new RenderingOptions();
options.showSucceeded = showSucceeded;
options.showFailed = showFailed;
options.showIgnored = showIgnored;
options.showNotRunned = showNotRun;
options.nameFilter = filterByName;
options.categories = GetSelectedCategories();
return options;
}
}
}
fileFormatVersion: 2
guid: 046c3854296c5ec48bac50da6ca248ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 046c3854296c5ec48bac50da6ca248ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
using System.Linq;
using UnityEditor.IMGUI.Controls;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine.TestRunner.NUnitExtensions;
using UnityEngine.TestTools.TestRunner.GUI;
using UnityEngine.TestRunner.NUnitExtensions.Filters;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class TestTreeViewBuilder
{
public List<TestRunnerResult> results = new List<TestRunnerResult>();
private readonly List<TestRunnerResult> m_OldTestResultList;
private readonly TestRunnerUIFilter m_UIFilter;
private readonly ITestAdaptor m_TestListRoot;
private readonly List<string> m_AvailableCategories = new List<string>();
public string[] AvailableCategories
{
get { return m_AvailableCategories.Distinct().OrderBy(a => a).ToArray(); }
}
public TestTreeViewBuilder(ITestAdaptor tests, List<TestRunnerResult> oldTestResultResults, TestRunnerUIFilter uiFilter)
{
m_AvailableCategories.Add(CategoryFilterExtended.k_DefaultCategory);
m_OldTestResultList = oldTestResultResults;
m_TestListRoot = tests;
m_UIFilter = uiFilter;
}
public TreeViewItem BuildTreeView(TestFilterSettings settings, bool sceneBased, string sceneName)
{
var rootItem = new TreeViewItem(int.MaxValue, 0, null, "Invisible Root Item");
ParseTestTree(0, rootItem, m_TestListRoot);
return rootItem;
}
private bool IsFilteredOutByUIFilter(ITestAdaptor test, TestRunnerResult result)
{
if (m_UIFilter.PassedHidden && result.resultStatus == TestRunnerResult.ResultStatus.Passed)
return true;
if (m_UIFilter.FailedHidden && (result.resultStatus == TestRunnerResult.ResultStatus.Failed || result.resultStatus == TestRunnerResult.ResultStatus.Inconclusive))
return true;
if (m_UIFilter.NotRunHidden && (result.resultStatus == TestRunnerResult.ResultStatus.NotRun || result.resultStatus == TestRunnerResult.ResultStatus.Skipped))
return true;
if (m_UIFilter.CategoryFilter.Length > 0)
return !test.Categories.Any(category => m_UIFilter.CategoryFilter.Contains(category));
return false;
}
private void ParseTestTree(int depth, TreeViewItem rootItem, ITestAdaptor testElement)
{
m_AvailableCategories.AddRange(testElement.Categories);
var testElementId = testElement.UniqueName;
if (!testElement.HasChildren)
{
var result = m_OldTestResultList.FirstOrDefault(a => a.uniqueId == testElementId);
if (result != null &&
(result.ignoredOrSkipped
|| result.notRunnable
|| testElement.RunState == RunState.NotRunnable
|| testElement.RunState == RunState.Ignored
|| testElement.RunState == RunState.Skipped
)
)
{
//if the test was or becomes ignored or not runnable, we recreate the result in case it has changed
result = null;
}
if (result == null)
{
result = new TestRunnerResult(testElement);
}
results.Add(result);
var test = new TestTreeViewItem(testElement, depth, rootItem);
if (!IsFilteredOutByUIFilter(testElement, result))
rootItem.AddChild(test);
test.SetResult(result);
return;
}
var groupResult = m_OldTestResultList.FirstOrDefault(a => a.uniqueId == testElementId);
if (groupResult == null)
{
groupResult = new TestRunnerResult(testElement);
}
results.Add(groupResult);
var group = new TestTreeViewItem(testElement, depth, rootItem);
group.SetResult(groupResult);
depth++;
foreach (var child in testElement.Children)
{
ParseTestTree(depth, group, child);
}
if (testElement.IsTestAssembly && !testElement.HasChildren)
return;
if (group.hasChildren)
rootItem.AddChild(group);
}
}
}
using System.Collections.Generic;
using System.Linq;
using UnityEditor.IMGUI.Controls;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine.TestRunner.NUnitExtensions;
using UnityEngine.TestTools.TestRunner.GUI;
using UnityEngine.TestRunner.NUnitExtensions.Filters;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class TestTreeViewBuilder
{
public List<TestRunnerResult> results = new List<TestRunnerResult>();
private readonly List<TestRunnerResult> m_OldTestResultList;
private readonly TestRunnerUIFilter m_UIFilter;
private readonly ITestAdaptor m_TestListRoot;
private readonly List<string> m_AvailableCategories = new List<string>();
public string[] AvailableCategories
{
get { return m_AvailableCategories.Distinct().OrderBy(a => a).ToArray(); }
}
public TestTreeViewBuilder(ITestAdaptor tests, List<TestRunnerResult> oldTestResultResults, TestRunnerUIFilter uiFilter)
{
m_AvailableCategories.Add(CategoryFilterExtended.k_DefaultCategory);
m_OldTestResultList = oldTestResultResults;
m_TestListRoot = tests;
m_UIFilter = uiFilter;
}
public TreeViewItem BuildTreeView(TestFilterSettings settings, bool sceneBased, string sceneName)
{
var rootItem = new TreeViewItem(int.MaxValue, 0, null, "Invisible Root Item");
ParseTestTree(0, rootItem, m_TestListRoot);
return rootItem;
}
private bool IsFilteredOutByUIFilter(ITestAdaptor test, TestRunnerResult result)
{
if (m_UIFilter.PassedHidden && result.resultStatus == TestRunnerResult.ResultStatus.Passed)
return true;
if (m_UIFilter.FailedHidden && (result.resultStatus == TestRunnerResult.ResultStatus.Failed || result.resultStatus == TestRunnerResult.ResultStatus.Inconclusive))
return true;
if (m_UIFilter.NotRunHidden && (result.resultStatus == TestRunnerResult.ResultStatus.NotRun || result.resultStatus == TestRunnerResult.ResultStatus.Skipped))
return true;
if (m_UIFilter.CategoryFilter.Length > 0)
return !test.Categories.Any(category => m_UIFilter.CategoryFilter.Contains(category));
return false;
}
private void ParseTestTree(int depth, TreeViewItem rootItem, ITestAdaptor testElement)
{
m_AvailableCategories.AddRange(testElement.Categories);
var testElementId = testElement.UniqueName;
if (!testElement.HasChildren)
{
var result = m_OldTestResultList.FirstOrDefault(a => a.uniqueId == testElementId);
if (result != null &&
(result.ignoredOrSkipped
|| result.notRunnable
|| testElement.RunState == RunState.NotRunnable
|| testElement.RunState == RunState.Ignored
|| testElement.RunState == RunState.Skipped
)
)
{
//if the test was or becomes ignored or not runnable, we recreate the result in case it has changed
result = null;
}
if (result == null)
{
result = new TestRunnerResult(testElement);
}
results.Add(result);
var test = new TestTreeViewItem(testElement, depth, rootItem);
if (!IsFilteredOutByUIFilter(testElement, result))
rootItem.AddChild(test);
test.SetResult(result);
return;
}
var groupResult = m_OldTestResultList.FirstOrDefault(a => a.uniqueId == testElementId);
if (groupResult == null)
{
groupResult = new TestRunnerResult(testElement);
}
results.Add(groupResult);
var group = new TestTreeViewItem(testElement, depth, rootItem);
group.SetResult(groupResult);
depth++;
foreach (var child in testElement.Children)
{
ParseTestTree(depth, group, child);
}
if (testElement.IsTestAssembly && !testElement.HasChildren)
return;
if (group.hasChildren)
rootItem.AddChild(group);
}
}
}
fileFormatVersion: 2
guid: e17c88b021c2a4c409b3f15b0d80ac62
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: e17c88b021c2a4c409b3f15b0d80ac62
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.IO;
using System.Linq;
using UnityEditor.ProjectWindowCallback;
using UnityEditor.Scripting.ScriptCompilation;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class TestListGUIHelper
{
private const string kResourcesTemplatePath = "Resources/ScriptTemplates";
private const string kAssemblyDefinitionTestTemplate = "92-Assembly Definition-NewTestAssembly.asmdef.txt";
private const string kAssemblyDefinitionEditModeTestTemplate =
"92-Assembly Definition-NewEditModeTestAssembly.asmdef.txt";
private const string kTestScriptTemplate = "83-C# Script-NewTestScript.cs.txt";
private const string kNewTestScriptName = "NewTestScript.cs";
private const string kNunit = "nunit.framework.dll";
[MenuItem("Assets/Create/Testing/Tests Assembly Folder", false, 83)]
public static void MenuItemAddFolderAndAsmDefForTesting()
{
AddFolderAndAsmDefForTesting();
}
[MenuItem("Assets/Create/Testing/Tests Assembly Folder", true, 83)]
public static bool MenuItemAddFolderAndAsmDefForTestingWithValidation()
{
return !SelectedFolderContainsTestAssembly();
}
public static void AddFolderAndAsmDefForTesting(bool isEditorOnly = false)
{
ProjectWindowUtil.CreateFolderWithTemplates("Tests",
isEditorOnly ? kAssemblyDefinitionEditModeTestTemplate : kAssemblyDefinitionTestTemplate);
}
public static bool SelectedFolderContainsTestAssembly()
{
var theNearestCustomScriptAssembly = GetTheNearestCustomScriptAssembly();
if (theNearestCustomScriptAssembly != null)
{
return theNearestCustomScriptAssembly.PrecompiledReferences != null && theNearestCustomScriptAssembly.PrecompiledReferences.Any(x => Path.GetFileName(x) == kNunit);
}
return false;
}
[MenuItem("Assets/Create/Testing/C# Test Script", false, 83)]
public static void AddTest()
{
var basePath = Path.Combine(EditorApplication.applicationContentsPath, kResourcesTemplatePath);
var destPath = Path.Combine(GetActiveFolderPath(), kNewTestScriptName);
var templatePath = Path.Combine(basePath, kTestScriptTemplate);
var icon = EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D;
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0,
ScriptableObject.CreateInstance<DoCreateScriptAsset>(), destPath, icon, templatePath);
AssetDatabase.Refresh();
}
[MenuItem("Assets/Create/Testing/C# Test Script", true, 83)]
public static bool CanAddScriptAndItWillCompile()
{
return CanAddEditModeTestScriptAndItWillCompile() || CanAddPlayModeTestScriptAndItWillCompile();
}
public static bool CanAddEditModeTestScriptAndItWillCompile()
{
var theNearestCustomScriptAssembly = GetTheNearestCustomScriptAssembly();
if (theNearestCustomScriptAssembly != null)
{
return (theNearestCustomScriptAssembly.AssemblyFlags & AssemblyFlags.EditorOnly) ==
AssemblyFlags.EditorOnly;
}
var activeFolderPath = GetActiveFolderPath();
return activeFolderPath.ToLower().Contains("/editor");
}
public static bool CanAddPlayModeTestScriptAndItWillCompile()
{
if (PlayerSettings.playModeTestRunnerEnabled)
{
return true;
}
var theNearestCustomScriptAssembly = GetTheNearestCustomScriptAssembly();
if (theNearestCustomScriptAssembly == null)
{
return false;
}
var hasTestAssemblyFlag = theNearestCustomScriptAssembly.PrecompiledReferences != null && theNearestCustomScriptAssembly.PrecompiledReferences.Any(x => Path.GetFileName(x) == kNunit);;
var editorOnlyAssembly = (theNearestCustomScriptAssembly.AssemblyFlags & AssemblyFlags.EditorOnly) != 0;
return hasTestAssemblyFlag && !editorOnlyAssembly;
}
public static string GetActiveFolderPath()
{
var path = "Assets";
foreach (var obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
{
path = AssetDatabase.GetAssetPath(obj);
if (!string.IsNullOrEmpty(path) && File.Exists(path))
{
path = Path.GetDirectoryName(path);
break;
}
}
return path;
}
private static CustomScriptAssembly GetTheNearestCustomScriptAssembly()
{
CustomScriptAssembly findCustomScriptAssemblyFromScriptPath;
try
{
findCustomScriptAssemblyFromScriptPath =
EditorCompilationInterface.Instance.FindCustomScriptAssemblyFromScriptPath(
Path.Combine(GetActiveFolderPath(), "Foo.cs"));
}
catch (Exception)
{
return null;
}
return findCustomScriptAssemblyFromScriptPath;
}
}
}
using System;
using System.IO;
using System.Linq;
using UnityEditor.ProjectWindowCallback;
using UnityEditor.Scripting.ScriptCompilation;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class TestListGUIHelper
{
private const string kResourcesTemplatePath = "Resources/ScriptTemplates";
private const string kAssemblyDefinitionTestTemplate = "92-Assembly Definition-NewTestAssembly.asmdef.txt";
private const string kAssemblyDefinitionEditModeTestTemplate =
"92-Assembly Definition-NewEditModeTestAssembly.asmdef.txt";
private const string kTestScriptTemplate = "83-C# Script-NewTestScript.cs.txt";
private const string kNewTestScriptName = "NewTestScript.cs";
private const string kNunit = "nunit.framework.dll";
[MenuItem("Assets/Create/Testing/Tests Assembly Folder", false, 83)]
public static void MenuItemAddFolderAndAsmDefForTesting()
{
AddFolderAndAsmDefForTesting();
}
[MenuItem("Assets/Create/Testing/Tests Assembly Folder", true, 83)]
public static bool MenuItemAddFolderAndAsmDefForTestingWithValidation()
{
return !SelectedFolderContainsTestAssembly();
}
public static void AddFolderAndAsmDefForTesting(bool isEditorOnly = false)
{
ProjectWindowUtil.CreateFolderWithTemplates("Tests",
isEditorOnly ? kAssemblyDefinitionEditModeTestTemplate : kAssemblyDefinitionTestTemplate);
}
public static bool SelectedFolderContainsTestAssembly()
{
var theNearestCustomScriptAssembly = GetTheNearestCustomScriptAssembly();
if (theNearestCustomScriptAssembly != null)
{
return theNearestCustomScriptAssembly.PrecompiledReferences != null && theNearestCustomScriptAssembly.PrecompiledReferences.Any(x => Path.GetFileName(x) == kNunit);
}
return false;
}
[MenuItem("Assets/Create/Testing/C# Test Script", false, 83)]
public static void AddTest()
{
var basePath = Path.Combine(EditorApplication.applicationContentsPath, kResourcesTemplatePath);
var destPath = Path.Combine(GetActiveFolderPath(), kNewTestScriptName);
var templatePath = Path.Combine(basePath, kTestScriptTemplate);
var icon = EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D;
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0,
ScriptableObject.CreateInstance<DoCreateScriptAsset>(), destPath, icon, templatePath);
AssetDatabase.Refresh();
}
[MenuItem("Assets/Create/Testing/C# Test Script", true, 83)]
public static bool CanAddScriptAndItWillCompile()
{
return CanAddEditModeTestScriptAndItWillCompile() || CanAddPlayModeTestScriptAndItWillCompile();
}
public static bool CanAddEditModeTestScriptAndItWillCompile()
{
var theNearestCustomScriptAssembly = GetTheNearestCustomScriptAssembly();
if (theNearestCustomScriptAssembly != null)
{
return (theNearestCustomScriptAssembly.AssemblyFlags & AssemblyFlags.EditorOnly) ==
AssemblyFlags.EditorOnly;
}
var activeFolderPath = GetActiveFolderPath();
return activeFolderPath.ToLower().Contains("/editor");
}
public static bool CanAddPlayModeTestScriptAndItWillCompile()
{
if (PlayerSettings.playModeTestRunnerEnabled)
{
return true;
}
var theNearestCustomScriptAssembly = GetTheNearestCustomScriptAssembly();
if (theNearestCustomScriptAssembly == null)
{
return false;
}
var hasTestAssemblyFlag = theNearestCustomScriptAssembly.PrecompiledReferences != null && theNearestCustomScriptAssembly.PrecompiledReferences.Any(x => Path.GetFileName(x) == kNunit);;
var editorOnlyAssembly = (theNearestCustomScriptAssembly.AssemblyFlags & AssemblyFlags.EditorOnly) != 0;
return hasTestAssemblyFlag && !editorOnlyAssembly;
}
public static string GetActiveFolderPath()
{
var path = "Assets";
foreach (var obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
{
path = AssetDatabase.GetAssetPath(obj);
if (!string.IsNullOrEmpty(path) && File.Exists(path))
{
path = Path.GetDirectoryName(path);
break;
}
}
return path;
}
private static CustomScriptAssembly GetTheNearestCustomScriptAssembly()
{
CustomScriptAssembly findCustomScriptAssemblyFromScriptPath;
try
{
findCustomScriptAssemblyFromScriptPath =
EditorCompilationInterface.Instance.FindCustomScriptAssemblyFromScriptPath(
Path.Combine(GetActiveFolderPath(), "Foo.cs"));
}
catch (Exception)
{
return null;
}
return findCustomScriptAssemblyFromScriptPath;
}
}
}
fileFormatVersion: 2
guid: 97a05971510726f438153cd4987526fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 97a05971510726f438153cd4987526fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 68cb547af0187634aad591a09c01cd5b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 68cb547af0187634aad591a09c01cd5b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal static class Icons
{
public static readonly Texture2D s_FailImg;
public static readonly Texture2D s_IgnoreImg;
public static readonly Texture2D s_SuccessImg;
public static readonly Texture2D s_UnknownImg;
public static readonly Texture2D s_InconclusiveImg;
public static readonly Texture2D s_StopwatchImg;
static Icons()
{
s_FailImg = EditorGUIUtility.IconContent("TestFailed").image as Texture2D;
s_IgnoreImg = EditorGUIUtility.IconContent("TestIgnored").image as Texture2D;
s_SuccessImg = EditorGUIUtility.IconContent("TestPassed").image as Texture2D;
s_UnknownImg = EditorGUIUtility.IconContent("TestNormal").image as Texture2D;
s_InconclusiveImg = EditorGUIUtility.IconContent("TestInconclusive").image as Texture2D;
s_StopwatchImg = EditorGUIUtility.IconContent("TestStopwatch").image as Texture2D;
}
}
}
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal static class Icons
{
public static readonly Texture2D s_FailImg;
public static readonly Texture2D s_IgnoreImg;
public static readonly Texture2D s_SuccessImg;
public static readonly Texture2D s_UnknownImg;
public static readonly Texture2D s_InconclusiveImg;
public static readonly Texture2D s_StopwatchImg;
static Icons()
{
s_FailImg = EditorGUIUtility.IconContent("TestFailed").image as Texture2D;
s_IgnoreImg = EditorGUIUtility.IconContent("TestIgnored").image as Texture2D;
s_SuccessImg = EditorGUIUtility.IconContent("TestPassed").image as Texture2D;
s_UnknownImg = EditorGUIUtility.IconContent("TestNormal").image as Texture2D;
s_InconclusiveImg = EditorGUIUtility.IconContent("TestInconclusive").image as Texture2D;
s_StopwatchImg = EditorGUIUtility.IconContent("TestStopwatch").image as Texture2D;
}
}
}
fileFormatVersion: 2
guid: 27769e9b00b038d47aefe306a4d20bec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 27769e9b00b038d47aefe306a4d20bec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
using NUnit.Framework.Interfaces;
using UnityEditor.IMGUI.Controls;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools.TestRunner;
using UnityEngine.TestTools.TestRunner.GUI;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class TestListTreeViewDataSource : TreeViewDataSource
{
private bool m_ExpandTreeOnCreation;
private readonly TestListGUI m_TestListGUI;
private ITestAdaptor m_RootTest;
public TestListTreeViewDataSource(TreeViewController testListTree, TestListGUI testListGUI, ITestAdaptor rootTest) : base(testListTree)
{
showRootItem = false;
rootIsCollapsable = false;
m_TestListGUI = testListGUI;
m_RootTest = rootTest;
}
public void UpdateRootTest(ITestAdaptor rootTest)
{
m_RootTest = rootTest;
}
public override void FetchData()
{
var sceneName = SceneManager.GetActiveScene().name;
if (sceneName.StartsWith("InitTestScene"))
sceneName = PlaymodeTestsController.GetController().settings.originalScene;
var testListBuilder = new TestTreeViewBuilder(m_RootTest, m_TestListGUI.newResultList, m_TestListGUI.m_TestRunnerUIFilter);
m_RootItem = testListBuilder.BuildTreeView(null, false, sceneName);
SetExpanded(m_RootItem, true);
if (m_RootItem.hasChildren && m_RootItem.children.Count == 1)
SetExpanded(m_RootItem.children[0], true);
if (m_ExpandTreeOnCreation)
SetExpandedWithChildren(m_RootItem, true);
m_TestListGUI.newResultList = new List<TestRunnerResult>(testListBuilder.results);
m_TestListGUI.m_TestRunnerUIFilter.availableCategories = testListBuilder.AvailableCategories;
m_NeedRefreshRows = true;
}
public override bool IsRenamingItemAllowed(TreeViewItem item)
{
return false;
}
public void ExpandTreeOnCreation()
{
m_ExpandTreeOnCreation = true;
}
public override bool IsExpandable(TreeViewItem item)
{
if (item is TestTreeViewItem)
return ((TestTreeViewItem)item).IsGroupNode;
return base.IsExpandable(item);
}
protected override List<TreeViewItem> Search(TreeViewItem rootItem, string search)
{
var result = new List<TreeViewItem>();
if (rootItem.hasChildren)
{
foreach (var child in rootItem.children)
{
SearchTestTree(child, search, result);
}
}
return result;
}
protected void SearchTestTree(TreeViewItem item, string search, IList<TreeViewItem> searchResult)
{
var testItem = item as TestTreeViewItem;
if (!testItem.IsGroupNode)
{
if (testItem.FullName.ToLower().Contains(search))
{
searchResult.Add(item);
}
}
else if (item.children != null)
{
foreach (var child in item.children)
SearchTestTree(child, search, searchResult);
}
}
}
}
using System.Collections.Generic;
using NUnit.Framework.Interfaces;
using UnityEditor.IMGUI.Controls;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools.TestRunner;
using UnityEngine.TestTools.TestRunner.GUI;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class TestListTreeViewDataSource : TreeViewDataSource
{
private bool m_ExpandTreeOnCreation;
private readonly TestListGUI m_TestListGUI;
private ITestAdaptor m_RootTest;
public TestListTreeViewDataSource(TreeViewController testListTree, TestListGUI testListGUI, ITestAdaptor rootTest) : base(testListTree)
{
showRootItem = false;
rootIsCollapsable = false;
m_TestListGUI = testListGUI;
m_RootTest = rootTest;
}
public void UpdateRootTest(ITestAdaptor rootTest)
{
m_RootTest = rootTest;
}
public override void FetchData()
{
var sceneName = SceneManager.GetActiveScene().name;
if (sceneName.StartsWith("InitTestScene"))
sceneName = PlaymodeTestsController.GetController().settings.originalScene;
var testListBuilder = new TestTreeViewBuilder(m_RootTest, m_TestListGUI.newResultList, m_TestListGUI.m_TestRunnerUIFilter);
m_RootItem = testListBuilder.BuildTreeView(null, false, sceneName);
SetExpanded(m_RootItem, true);
if (m_RootItem.hasChildren && m_RootItem.children.Count == 1)
SetExpanded(m_RootItem.children[0], true);
if (m_ExpandTreeOnCreation)
SetExpandedWithChildren(m_RootItem, true);
m_TestListGUI.newResultList = new List<TestRunnerResult>(testListBuilder.results);
m_TestListGUI.m_TestRunnerUIFilter.availableCategories = testListBuilder.AvailableCategories;
m_NeedRefreshRows = true;
}
public override bool IsRenamingItemAllowed(TreeViewItem item)
{
return false;
}
public void ExpandTreeOnCreation()
{
m_ExpandTreeOnCreation = true;
}
public override bool IsExpandable(TreeViewItem item)
{
if (item is TestTreeViewItem)
return ((TestTreeViewItem)item).IsGroupNode;
return base.IsExpandable(item);
}
protected override List<TreeViewItem> Search(TreeViewItem rootItem, string search)
{
var result = new List<TreeViewItem>();
if (rootItem.hasChildren)
{
foreach (var child in rootItem.children)
{
SearchTestTree(child, search, result);
}
}
return result;
}
protected void SearchTestTree(TreeViewItem item, string search, IList<TreeViewItem> searchResult)
{
var testItem = item as TestTreeViewItem;
if (!testItem.IsGroupNode)
{
if (testItem.FullName.ToLower().Contains(search))
{
searchResult.Add(item);
}
}
else if (item.children != null)
{
foreach (var child in item.children)
SearchTestTree(child, search, searchResult);
}
}
}
}
fileFormatVersion: 2
guid: ce87c287371edde43a4b5fcfdee7b9ef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ce87c287371edde43a4b5fcfdee7b9ef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEditor.IMGUI.Controls;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class TestListTreeViewGUI : TreeViewGUI
{
public TestListTreeViewGUI(TreeViewController testListTree) : base(testListTree)
{
}
}
}
using UnityEditor.IMGUI.Controls;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal class TestListTreeViewGUI : TreeViewGUI
{
public TestListTreeViewGUI(TreeViewController testListTree) : base(testListTree)
{
}
}
}
fileFormatVersion: 2
guid: 52c907c81459f324497af504b84fd557
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 52c907c81459f324497af504b84fd557
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Reflection;
using System.Text;
using UnityEditor.IMGUI.Controls;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine.TestTools.TestRunner.GUI;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal sealed class TestTreeViewItem : TreeViewItem
{
public TestRunnerResult result;
internal ITestAdaptor m_Test;
public Type type;
public MethodInfo method;
private const int k_ResultTestMaxLength = 15000;
public bool IsGroupNode { get { return m_Test.IsSuite; } }
public string FullName { get { return m_Test.FullName; } }
public string GetAssemblyName()
{
var test = m_Test;
while (test != null)
{
if (test.IsTestAssembly)
{
return test.FullName;
}
test = test.Parent;
}
return null;
}
public TestTreeViewItem(ITestAdaptor test, int depth, TreeViewItem parent)
: base(GetId(test), depth, parent, test.Name)
{
m_Test = test;
if (test.TypeInfo != null)
{
type = test.TypeInfo.Type;
}
if (test.Method != null)
{
method = test.Method.MethodInfo;
}
displayName = test.Name.Replace("\n", "");
icon = Icons.s_UnknownImg;
}
private static int GetId(ITestAdaptor test)
{
return test.UniqueName.GetHashCode();
}
public void SetResult(TestRunnerResult testResult)
{
result = testResult;
result.SetResultChangedCallback(ResultUpdated);
ResultUpdated(result);
}
public string GetResultText()
{
var durationString = String.Format("{0:0.000}", result.duration);
var sb = new StringBuilder(string.Format("{0} ({1}s)", displayName.Trim(), durationString));
if (!string.IsNullOrEmpty(result.description))
{
sb.AppendFormat("\n{0}", result.description);
}
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 (!string.IsNullOrEmpty(result.output))
{
sb.Append("\n---\n");
sb.Append(result.output.Trim());
}
if (sb.Length > k_ResultTestMaxLength)
{
sb.Length = k_ResultTestMaxLength;
sb.AppendFormat("...\n\n---MESSAGE TRUNCATED AT {0} CHARACTERS---", k_ResultTestMaxLength);
}
return sb.ToString().Trim();
}
private void ResultUpdated(TestRunnerResult testResult)
{
switch (testResult.resultStatus)
{
case TestRunnerResult.ResultStatus.Passed:
icon = Icons.s_SuccessImg;
break;
case TestRunnerResult.ResultStatus.Failed:
icon = Icons.s_FailImg;
break;
case TestRunnerResult.ResultStatus.Inconclusive:
icon = Icons.s_InconclusiveImg;
break;
case TestRunnerResult.ResultStatus.Skipped:
icon = Icons.s_IgnoreImg;
break;
default:
if (testResult.ignoredOrSkipped)
{
icon = Icons.s_IgnoreImg;
}
else if (testResult.notRunnable)
{
icon = Icons.s_FailImg;
}
else
{
icon = Icons.s_UnknownImg;
}
break;
}
}
}
}
using System;
using System.Reflection;
using System.Text;
using UnityEditor.IMGUI.Controls;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine.TestTools.TestRunner.GUI;
namespace UnityEditor.TestTools.TestRunner.GUI
{
internal sealed class TestTreeViewItem : TreeViewItem
{
public TestRunnerResult result;
internal ITestAdaptor m_Test;
public Type type;
public MethodInfo method;
private const int k_ResultTestMaxLength = 15000;
public bool IsGroupNode { get { return m_Test.IsSuite; } }
public string FullName { get { return m_Test.FullName; } }
public string GetAssemblyName()
{
var test = m_Test;
while (test != null)
{
if (test.IsTestAssembly)
{
return test.FullName;
}
test = test.Parent;
}
return null;
}
public TestTreeViewItem(ITestAdaptor test, int depth, TreeViewItem parent)
: base(GetId(test), depth, parent, test.Name)
{
m_Test = test;
if (test.TypeInfo != null)
{
type = test.TypeInfo.Type;
}
if (test.Method != null)
{
method = test.Method.MethodInfo;
}
displayName = test.Name.Replace("\n", "");
icon = Icons.s_UnknownImg;
}
private static int GetId(ITestAdaptor test)
{
return test.UniqueName.GetHashCode();
}
public void SetResult(TestRunnerResult testResult)
{
result = testResult;
result.SetResultChangedCallback(ResultUpdated);
ResultUpdated(result);
}
public string GetResultText()
{
var durationString = String.Format("{0:0.000}", result.duration);
var sb = new StringBuilder(string.Format("{0} ({1}s)", displayName.Trim(), durationString));
if (!string.IsNullOrEmpty(result.description))
{
sb.AppendFormat("\n{0}", result.description);
}
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 (!string.IsNullOrEmpty(result.output))
{
sb.Append("\n---\n");
sb.Append(result.output.Trim());
}
if (sb.Length > k_ResultTestMaxLength)
{
sb.Length = k_ResultTestMaxLength;
sb.AppendFormat("...\n\n---MESSAGE TRUNCATED AT {0} CHARACTERS---", k_ResultTestMaxLength);
}
return sb.ToString().Trim();
}
private void ResultUpdated(TestRunnerResult testResult)
{
switch (testResult.resultStatus)
{
case TestRunnerResult.ResultStatus.Passed:
icon = Icons.s_SuccessImg;
break;
case TestRunnerResult.ResultStatus.Failed:
icon = Icons.s_FailImg;
break;
case TestRunnerResult.ResultStatus.Inconclusive:
icon = Icons.s_InconclusiveImg;
break;
case TestRunnerResult.ResultStatus.Skipped:
icon = Icons.s_IgnoreImg;
break;
default:
if (testResult.ignoredOrSkipped)
{
icon = Icons.s_IgnoreImg;
}
else if (testResult.notRunnable)
{
icon = Icons.s_FailImg;
}
else
{
icon = Icons.s_UnknownImg;
}
break;
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment