diff options
Diffstat (limited to 'Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/TestRunner/Callbacks/TestResultRenderer.cs')
| -rw-r--r-- | Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/TestRunner/Callbacks/TestResultRenderer.cs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/TestRunner/Callbacks/TestResultRenderer.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/TestRunner/Callbacks/TestResultRenderer.cs new file mode 100644 index 0000000..95316e7 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/TestRunner/Callbacks/TestResultRenderer.cs @@ -0,0 +1,97 @@ +using System.Collections.Generic;
+using System.Linq;
+using NUnit.Framework.Interfaces;
+using NUnit.Framework.Internal;
+
+namespace UnityEngine.TestTools.TestRunner.Callbacks
+{
+ internal class TestResultRenderer
+ {
+ private static class Styles
+ {
+ public static readonly GUIStyle SucceedLabelStyle;
+ public static readonly GUIStyle FailedLabelStyle;
+ public static readonly GUIStyle FailedMessagesStyle;
+
+ static Styles()
+ {
+ SucceedLabelStyle = new GUIStyle("label");
+ SucceedLabelStyle.normal.textColor = Color.green;
+ SucceedLabelStyle.fontSize = 48;
+
+ FailedLabelStyle = new GUIStyle("label");
+ FailedLabelStyle.normal.textColor = Color.red;
+ FailedLabelStyle.fontSize = 32;
+
+ FailedMessagesStyle = new GUIStyle("label");
+ FailedMessagesStyle.wordWrap = false;
+ FailedMessagesStyle.richText = true;
+ }
+ }
+
+ private readonly List<ITestResult> m_FailedTestCollection;
+
+ private bool m_ShowResults;
+ private Vector2 m_ScrollPosition;
+
+ public TestResultRenderer(ITestResult testResults)
+ {
+ m_FailedTestCollection = new List<ITestResult>();
+ GetFailedTests(testResults);
+ }
+
+ private void GetFailedTests(ITestResult testResults)
+ {
+ if (testResults is TestCaseResult)
+ {
+ if (testResults.ResultState.Status == TestStatus.Failed)
+ m_FailedTestCollection.Add(testResults);
+ }
+ else if (testResults.HasChildren)
+ {
+ foreach (var testResultsChild in testResults.Children)
+ {
+ GetFailedTests(testResultsChild);
+ }
+ }
+ }
+
+ private const int k_MaxStringLength = 15000;
+
+ public void ShowResults()
+ {
+ m_ShowResults = true;
+ Cursor.visible = true;
+ }
+
+ public void Draw()
+ {
+ if (!m_ShowResults) return;
+ if (m_FailedTestCollection.Count == 0)
+ {
+ GUILayout.Label("All test(s) succeeded", Styles.SucceedLabelStyle, GUILayout.Width(600));
+ }
+ else
+ {
+ int count = m_FailedTestCollection.Count;
+ GUILayout.Label(count + " tests failed!", Styles.FailedLabelStyle);
+
+ m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition, GUILayout.ExpandWidth(true));
+ var text = "";
+
+ text += "<b><size=18>Code-based tests</size></b>\n";
+ text += string.Join("\n", m_FailedTestCollection
+ .Select(result => result.Name + " " + result.ResultState + "\n" + result.Message)
+ .ToArray());
+
+ if (text.Length > k_MaxStringLength)
+ text = text.Substring(0, k_MaxStringLength);
+
+ GUILayout.TextArea(text, Styles.FailedMessagesStyle);
+ GUILayout.EndScrollView();
+ }
+ if (GUILayout.Button("Close"))
+ Application.Quit();
+ }
+ }
+}
|
