Initial Commit
This commit is contained in:
parent
53eb92e9af
commit
270ab7d11f
15341 changed files with 700234 additions and 0 deletions
|
@ -0,0 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
interface ITestRunnerApiMapper
|
||||
{
|
||||
string GetRunStateFromResultNunitXml(ITestResultAdaptor result);
|
||||
TestState GetTestStateFromResult(ITestResultAdaptor result);
|
||||
List<string> FlattenTestNames(ITestAdaptor testsToRun);
|
||||
TestPlanMessage MapTestToTestPlanMessage(ITestAdaptor testsToRun);
|
||||
TestStartedMessage MapTestToTestStartedMessage(ITestAdaptor test);
|
||||
TestFinishedMessage TestResultToTestFinishedMessage(ITestResultAdaptor result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6de79ae237e51554da96fd28f68b66a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,7 @@
|
|||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
interface IUtpLogger
|
||||
{
|
||||
void Log(Message msg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9014630255533ed42915965b4065cde8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEditor.Compilation;
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
internal interface IUtpMessageReporter
|
||||
{
|
||||
void ReportTestFinished(ITestResultAdaptor result);
|
||||
void ReportTestRunStarted(ITestAdaptor testsToRun);
|
||||
void ReportTestStarted(ITestAdaptor test);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 952b3dc7b47846947b37c8d3ae46579a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
[Serializable]
|
||||
internal abstract class Message
|
||||
{
|
||||
public string type;
|
||||
// Milliseconds since unix epoch
|
||||
public ulong time;
|
||||
public int version;
|
||||
public string phase;
|
||||
public int processId;
|
||||
|
||||
protected Message()
|
||||
{
|
||||
version = 2;
|
||||
phase = "Immediate";
|
||||
processId = Process.GetCurrentProcess().Id;
|
||||
AddTimeStamp();
|
||||
}
|
||||
|
||||
public void AddTimeStamp()
|
||||
{
|
||||
time = Convert.ToUInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 321dc2c0720f8dd4f9396ecdc12b8746
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
|||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
internal class TestFinishedMessage : Message
|
||||
{
|
||||
public string name;
|
||||
public TestState state;
|
||||
public string message;
|
||||
public ulong duration; // milliseconds
|
||||
public ulong durationMicroseconds;
|
||||
public string stackTrace;
|
||||
|
||||
public TestFinishedMessage()
|
||||
{
|
||||
type = "TestStatus";
|
||||
phase = "End";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 423fe2ef878fa1140a7e1f7f9e365815
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
internal class TestPlanMessage : Message
|
||||
{
|
||||
public List<string> tests;
|
||||
|
||||
public TestPlanMessage()
|
||||
{
|
||||
type = "TestPlan";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 28f79a0d7e64c2345bc46f8c4cf788f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,93 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
internal class TestRunnerApiMapper : ITestRunnerApiMapper
|
||||
{
|
||||
public TestPlanMessage MapTestToTestPlanMessage(ITestAdaptor testsToRun)
|
||||
{
|
||||
var testsNames = testsToRun != null ? FlattenTestNames(testsToRun) : new List<string>();
|
||||
|
||||
var msg = new TestPlanMessage
|
||||
{
|
||||
tests = testsNames
|
||||
};
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
public TestStartedMessage MapTestToTestStartedMessage(ITestAdaptor test)
|
||||
{
|
||||
return new TestStartedMessage
|
||||
{
|
||||
name = test.FullName
|
||||
};
|
||||
}
|
||||
|
||||
public TestFinishedMessage TestResultToTestFinishedMessage(ITestResultAdaptor result)
|
||||
{
|
||||
return new TestFinishedMessage
|
||||
{
|
||||
name = result.Test.FullName,
|
||||
duration = Convert.ToUInt64(result.Duration * 1000),
|
||||
durationMicroseconds = Convert.ToUInt64(result.Duration * 1000000),
|
||||
message = result.Message,
|
||||
state = GetTestStateFromResult(result),
|
||||
stackTrace = result.StackTrace
|
||||
};
|
||||
}
|
||||
|
||||
public string GetRunStateFromResultNunitXml(ITestResultAdaptor result)
|
||||
{
|
||||
var doc = new XmlDocument();
|
||||
doc.LoadXml(result.ToXml().OuterXml);
|
||||
return doc.FirstChild.Attributes["runstate"].Value;
|
||||
}
|
||||
|
||||
public TestState GetTestStateFromResult(ITestResultAdaptor result)
|
||||
{
|
||||
var state = TestState.Failure;
|
||||
|
||||
if (result.TestStatus == TestStatus.Passed)
|
||||
{
|
||||
state = TestState.Success;
|
||||
}
|
||||
else if (result.TestStatus == TestStatus.Skipped)
|
||||
{
|
||||
state = TestState.Skipped;
|
||||
|
||||
if (result.ResultState.ToLowerInvariant().EndsWith("ignored"))
|
||||
state = TestState.Ignored;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result.ResultState.ToLowerInvariant().Equals("inconclusive"))
|
||||
state = TestState.Inconclusive;
|
||||
|
||||
if (result.ResultState.ToLowerInvariant().EndsWith("cancelled") ||
|
||||
result.ResultState.ToLowerInvariant().EndsWith("error"))
|
||||
state = TestState.Error;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
public List<string> FlattenTestNames(ITestAdaptor test)
|
||||
{
|
||||
var results = new List<string>();
|
||||
|
||||
if (!test.IsSuite)
|
||||
results.Add(test.FullName);
|
||||
|
||||
if (test.Children != null && test.Children.Any())
|
||||
foreach (var child in test.Children)
|
||||
results.AddRange(FlattenTestNames(child));
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2011a59d3f76b3d4a85cb53f945fceee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
internal class TestStartedMessage : Message
|
||||
{
|
||||
public string name;
|
||||
public TestState state;
|
||||
|
||||
public TestStartedMessage()
|
||||
{
|
||||
type = "TestStatus";
|
||||
phase = "Begin";
|
||||
state = TestState.Inconclusive;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd3e81baa10021f4d877fa36382bab16
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,13 @@
|
|||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
// This matches the state definitions expected by the Perl code, which in turn matches the NUnit 2 values...
|
||||
internal enum TestState
|
||||
{
|
||||
Inconclusive = 0,
|
||||
Skipped = 2,
|
||||
Ignored = 3,
|
||||
Success = 4,
|
||||
Failure = 5,
|
||||
Error = 6
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 77f432980bb30084299a138e15c6f571
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,35 @@
|
|||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
internal class UnityTestProtocolListener : ScriptableObject, ICallbacks
|
||||
{
|
||||
private IUtpMessageReporter m_UtpMessageReporter;
|
||||
|
||||
public UnityTestProtocolListener()
|
||||
{
|
||||
m_UtpMessageReporter = new UtpMessageReporter(new UtpDebugLogger());
|
||||
}
|
||||
|
||||
public void RunStarted(ITestAdaptor testsToRun)
|
||||
{
|
||||
m_UtpMessageReporter.ReportTestRunStarted(testsToRun);
|
||||
}
|
||||
|
||||
public void RunFinished(ITestResultAdaptor testResults)
|
||||
{
|
||||
// Apparently does nothing :)
|
||||
}
|
||||
|
||||
public void TestStarted(ITestAdaptor test)
|
||||
{
|
||||
m_UtpMessageReporter.ReportTestStarted(test);
|
||||
}
|
||||
|
||||
public void TestFinished(ITestResultAdaptor result)
|
||||
{
|
||||
m_UtpMessageReporter.ReportTestFinished(result);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 900aac3710bc14542a8d164e3f0ff820
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using UnityEditor.Compilation;
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
internal static class UnityTestProtocolStarter
|
||||
{
|
||||
static UnityTestProtocolStarter()
|
||||
{
|
||||
var commandLineArgs = Environment.GetCommandLineArgs();
|
||||
if (commandLineArgs.Contains("-automated") && commandLineArgs.Contains("-runTests")) // wanna have it only for utr run
|
||||
{
|
||||
var api = ScriptableObject.CreateInstance<TestRunnerApi>();
|
||||
var listener = ScriptableObject.CreateInstance<UnityTestProtocolListener>();
|
||||
api.RegisterCallbacks(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1ac58cb55fc8daf4abd3945a2bbbb0c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,13 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
class UtpDebugLogger : IUtpLogger
|
||||
{
|
||||
public void Log(Message msg)
|
||||
{
|
||||
var msgJson = JsonUtility.ToJson(msg);
|
||||
Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "\n##utp:{0}", msgJson);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d0abdd8cb6b29a24c8ee19626ef741b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,46 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor.Compilation;
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
|
||||
{
|
||||
internal class UtpMessageReporter : IUtpMessageReporter
|
||||
{
|
||||
public ITestRunnerApiMapper TestRunnerApiMapper;
|
||||
public IUtpLogger Logger;
|
||||
|
||||
public UtpMessageReporter(IUtpLogger utpLogger)
|
||||
{
|
||||
TestRunnerApiMapper = new TestRunnerApiMapper();
|
||||
Logger = utpLogger;
|
||||
}
|
||||
|
||||
public void ReportTestRunStarted(ITestAdaptor testsToRun)
|
||||
{
|
||||
var msg = TestRunnerApiMapper.MapTestToTestPlanMessage(testsToRun);
|
||||
|
||||
Logger.Log(msg);
|
||||
}
|
||||
|
||||
public void ReportTestStarted(ITestAdaptor test)
|
||||
{
|
||||
if (test.IsSuite)
|
||||
return;
|
||||
|
||||
var msg = TestRunnerApiMapper.MapTestToTestStartedMessage(test);
|
||||
|
||||
Logger.Log(msg);
|
||||
}
|
||||
|
||||
public void ReportTestFinished(ITestResultAdaptor result)
|
||||
{
|
||||
if (result.Test.IsSuite)
|
||||
return;
|
||||
|
||||
var msg = TestRunnerApiMapper.TestResultToTestFinishedMessage(result);
|
||||
|
||||
Logger.Log(msg);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ebcc5f899d9277642868aeda9a17cbaf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue