Skip to content

Commit

Permalink
1.0.7-headless1 - 2019/03/18
Browse files Browse the repository at this point in the history
@2019.2
  • Loading branch information
ErikMoczi committed Mar 19, 2019
1 parent 5ea5079 commit de5fb55
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.0.7] - 2018-11-15
## [1.0.7-headless1] - 2018-11-15

### This is the first release of *Unity Package com.unity.test-framework*.

Expand Down
13 changes: 9 additions & 4 deletions package/UnityEditor.TestRunner/Api/CallbacksDelegator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ public void RunFinishedRemotely(byte[] testResultsData)

public void RunFailed(string failureMessage)
{
var nunitTestResult = new TestSuiteResult(new TestSuite("test"));
nunitTestResult.SetResult(ResultState.Error, failureMessage);
var testResult = m_AdaptorFactory.Create(nunitTestResult);
TryInvokeAllCallbacks(callbacks => callbacks.RunFinished(testResult));
Debug.LogError(failureMessage);
TryInvokeAllCallbacks(callbacks =>
{
var errorCallback = callbacks as IErrorCallbacks;
if (errorCallback != null)
{
errorCallback.OnError(failureMessage);
}
});
}

public void TestStarted(ITest test)
Expand Down
2 changes: 2 additions & 0 deletions package/UnityEditor.TestRunner/Api/ExecutionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ internal class ExecutionSettings
public BuildTarget? targetPlatform;
public ITestRunSettings overloadTestRunSettings;
public Filter filter;
public string testPlayerPath;
public bool doNotLaunchTestPlayer;
}
}
7 changes: 7 additions & 0 deletions package/UnityEditor.TestRunner/Api/IErrorCallbacks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace UnityEditor.TestTools.TestRunner.Api
{
internal interface IErrorCallbacks : ICallbacks
{
void OnError(string message);
}
}
11 changes: 8 additions & 3 deletions package/UnityEditor.TestRunner/Api/TestLauncherFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static TestLauncherBase GetPlayModeLauncher(PlaymodeTestsControllerSettings sett
{
if (executionSettings.targetPlatform != null)
{
return GetPlayerLauncher(settings, executionSettings.targetPlatform.Value, executionSettings.overloadTestRunSettings);
return GetPlayerLauncher(settings, executionSettings);
}

if (PlayerSettings.runPlayModeTestAsEditModeTest)
Expand All @@ -49,9 +49,14 @@ static TestLauncherBase GetPlayModeLauncher(PlaymodeTestsControllerSettings sett
return new PlaymodeLauncher(settings);
}

static TestLauncherBase GetPlayerLauncher(PlaymodeTestsControllerSettings settings, BuildTarget targetPlatform, ITestRunSettings overloadTestRunSettings)
static TestLauncherBase GetPlayerLauncher(PlaymodeTestsControllerSettings settings, ExecutionSettings executionSettings)
{
return new PlayerLauncher(settings, targetPlatform, overloadTestRunSettings);
return new PlayerLauncher(
settings,
executionSettings.targetPlatform.Value,
executionSettings.overloadTestRunSettings,
executionSettings.testPlayerPath,
executionSettings.doNotLaunchTestPlayer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace UnityEditor.TestTools.TestRunner.CommandLineTest
{
[Serializable]
internal class ExitCallbacks : ScriptableObject, ICallbacks
internal class ExitCallbacks : ScriptableObject, IErrorCallbacks
{
private bool m_AnyTestsExecuted;
private bool m_RunFailed;
Expand Down Expand Up @@ -39,5 +39,10 @@ public void TestFinished(ITestResultAdaptor result)
public void RunStarted(ITestAdaptor testsToRun)
{
}

public void OnError(string message)
{
EditorApplication.Exit((int)Executer.ReturnCodes.Failed);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public Api.ExecutionSettings BuildApiExecutionSettings(string[] commandLineArgs)
string[] testFilters = null;
string[] testCategories = null;
string testSettingsFilePath = null;
string testPlayerPath = null;
bool doNotLaunchTestPlayer = false;

var optionSet = new CommandLineOptionSet(
new CommandLineOption("quit", () => { quit = true; }),
Expand All @@ -36,7 +38,9 @@ public Api.ExecutionSettings BuildApiExecutionSettings(string[] commandLineArgs)
new CommandLineOption("testFilter", filters => { testFilters = filters; }),
new CommandLineOption("editorTestsCategories", catagories => { testCategories = catagories; }),
new CommandLineOption("testCategory", catagories => { testCategories = catagories; }),
new CommandLineOption("testSettingsFile", settingsFilePath => { testSettingsFilePath = settingsFilePath; })
new CommandLineOption("testSettingsFile", settingsFilePath => { testSettingsFilePath = settingsFilePath; }),
new CommandLineOption("testPlayerPath", path => { testPlayerPath = path; }),
new CommandLineOption("doNotLaunchTestPlayer", () => { doNotLaunchTestPlayer = true; })
);
optionSet.Parse(commandLineArgs);

Expand All @@ -60,7 +64,9 @@ public Api.ExecutionSettings BuildApiExecutionSettings(string[] commandLineArgs)
{
filter = filter,
overloadTestRunSettings = new RunSettings(testSettings),
targetPlatform = buildTarget
targetPlatform = buildTarget,
testPlayerPath = testPlayerPath,
doNotLaunchTestPlayer = doNotLaunchTestPlayer
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ private static bool IsTestEnabledOnPlatform(ITest test, RuntimePlatform testTarg

private IEnumerable<Type> GetTypesFromPrebuildAttributes(IEnumerable<ITest> tests)
{
var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
var attributesFromAssemblies = allAssemblies.SelectMany(assembly => assembly.GetCustomAttributes(typeof(T2), true).OfType<T2>());
var attributesFromMethods = tests.SelectMany(t => t.Method.GetCustomAttributes<T2>(true).Select(attribute => attribute));
var attributesFromTypes = tests.SelectMany(t => t.Method.TypeInfo.GetCustomAttributes<T2>(true).Select(attribute => attribute));

var result = new List<T2>();
result.AddRange(attributesFromAssemblies);
result.AddRange(attributesFromMethods);
result.AddRange(attributesFromTypes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestRunner.Utils;
using UnityEngine.TestTools;
using UnityEngine.TestTools.TestRunner;
using UnityEngine.TestTools.TestRunner.GUI;
Expand Down Expand Up @@ -50,6 +51,7 @@ public override void Run()

m_EditModeRunner.Run();
AddEventHandler<BackgroundListener>();
AddEventHandler<TestRunCallbackListener>();
}

private static bool OpenNewScene(out SceneSetup[] previousSceneSetup)
Expand Down
72 changes: 45 additions & 27 deletions package/UnityEditor.TestRunner/TestLaunchers/PlayerLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestRunner.Utils;
using UnityEngine.TestTools.TestRunner;
using UnityEngine.TestTools.TestRunner.Callbacks;

Expand All @@ -23,14 +24,18 @@ internal class PlayerLauncher : RuntimeTestLauncherBase
{
private readonly PlaymodeTestsControllerSettings m_Settings;
private readonly BuildTarget m_TargetPlatform;
private string m_TempBuildLocation;
private ITestRunSettings m_OverloadTestRunSettings;
private string m_TestPlayerPath;
private bool m_DoNotLaunchTestPlayer;
private string m_SceneName;

public PlayerLauncher(PlaymodeTestsControllerSettings settings, BuildTarget? targetPlatform, ITestRunSettings overloadTestRunSettings)
public PlayerLauncher(PlaymodeTestsControllerSettings settings, BuildTarget? targetPlatform, ITestRunSettings overloadTestRunSettings, string testPlayerPath = null, bool doNotLaunchTestPlayer = false)
{
m_Settings = settings;
m_TargetPlatform = targetPlatform ?? EditorUserBuildSettings.activeBuildTarget;
m_OverloadTestRunSettings = overloadTestRunSettings;
m_TestPlayerPath = testPlayerPath;
m_DoNotLaunchTestPlayer = doNotLaunchTestPlayer;
}

protected override RuntimePlatform? TestTargetPlatform
Expand All @@ -49,16 +54,16 @@ public override void Run()

using (var settings = new PlayerLauncherContextSettings(m_OverloadTestRunSettings))
{
var sceneName = CreateSceneName();
var scene = PrepareScene(sceneName);
m_SceneName = CreateSceneName();
var scene = PrepareScene(m_SceneName);

var filter = m_Settings.filter.BuildNUnitFilter();
var runner = LoadTests(filter);
var exceptionThrown = ExecutePreBuildSetupMethods(runner.LoadedTest, filter);
if (exceptionThrown)
{
ReopenOriginalScene(m_Settings.originalScene);
AssetDatabase.DeleteAsset(sceneName);
AssetDatabase.DeleteAsset(m_SceneName);
CallbacksDelegator.instance.RunFailed("Run Failed: One or more errors in a prebuild setup. See the editor log for details.");
return;
}
Expand All @@ -70,7 +75,7 @@ public override void Run()
ExecutePostBuildCleanupMethods(runner.LoadedTest, filter);

ReopenOriginalScene(m_Settings.originalScene);
AssetDatabase.DeleteAsset(sceneName);
AssetDatabase.DeleteAsset(m_SceneName);

if (!success)
{
Expand All @@ -80,6 +85,11 @@ public override void Run()
}

editorConnectionTestCollector.PostSuccessfulBuildAction();

if (m_DoNotLaunchTestPlayer)
{
EditorApplication.Exit(0);
}
}
}

Expand All @@ -90,6 +100,7 @@ public Scene PrepareScene(string sceneName)
runner.AddEventHandlerMonoBehaviour<PlayModeRunnerCallback>();
runner.settings = m_Settings;
runner.AddEventHandlerMonoBehaviour<RemoteTestResultSender>();
runner.AddEventHandlerScriptableObject<TestRunCallbackListener>();
});
return scene;
}
Expand Down Expand Up @@ -133,21 +144,18 @@ private PlayerLauncherBuildOptions GetBuildOptions(Scene scene)
scenes.AddRange(EditorBuildSettings.scenes.Select(x => x.path));
buildOptions.scenes = scenes.ToArray();

buildOptions.options |= BuildOptions.AutoRunPlayer | BuildOptions.Development | BuildOptions.ConnectToHost | BuildOptions.IncludeTestAssemblies | BuildOptions.StrictMode;
buildOptions.options |= BuildOptions.Development | BuildOptions.ConnectToHost | BuildOptions.IncludeTestAssemblies | BuildOptions.StrictMode;
if (!m_DoNotLaunchTestPlayer)
{
buildOptions.options |= BuildOptions.AutoRunPlayer;
}

buildOptions.target = m_TargetPlatform;

if (EditorUserBuildSettings.waitForPlayerConnection)
buildOptions.options |= BuildOptions.WaitForPlayerConnection;

var buildTargetGroup = EditorUserBuildSettings.activeBuildTargetGroup;
var uniqueTempPathInProject = FileUtil.GetUniqueTempPathInProject();

if (reduceBuildLocationPathLength)
{
uniqueTempPathInProject = Path.GetTempFileName();
File.Delete(uniqueTempPathInProject);
Directory.CreateDirectory(uniqueTempPathInProject);
}

//Check if Lz4 is supported for the current buildtargetgroup and enable it if need be
if (PostprocessBuildPlayer.SupportsLz4Compression(buildTargetGroup, m_TargetPlatform))
Expand All @@ -158,27 +166,37 @@ private PlayerLauncherBuildOptions GetBuildOptions(Scene scene)
buildOptions.options |= BuildOptions.CompressWithLz4HC;
}

m_TempBuildLocation = Path.GetFullPath(uniqueTempPathInProject);
string buildLocation;
if (!string.IsNullOrEmpty(m_TestPlayerPath))
{
buildLocation = m_TestPlayerPath;
}
else
{
var uniqueTempPathInProject = FileUtil.GetUniqueTempPathInProject();
var playerDirectoryName = reduceBuildLocationPathLength ? "PwT" : "PlayerWithTests";

if (reduceBuildLocationPathLength)
{
uniqueTempPathInProject = Path.GetTempFileName();
File.Delete(uniqueTempPathInProject);
Directory.CreateDirectory(uniqueTempPathInProject);
}
var tempPath = Path.GetFullPath(uniqueTempPathInProject);
buildLocation = Path.Combine(tempPath, playerDirectoryName);
}

string extensionForBuildTarget = PostprocessBuildPlayer.GetExtensionForBuildTarget(buildTargetGroup, buildOptions.target, buildOptions.options);

var playerExecutableName = "PlayerWithTests";
var playerDirectoryName = reduceBuildLocationPathLength ? "PwT" : "PlayerWithTests";

var locationPath = Path.Combine(m_TempBuildLocation, playerDirectoryName);

if (!string.IsNullOrEmpty(extensionForBuildTarget))
{
playerExecutableName += string.Format(".{0}", extensionForBuildTarget);
locationPath = Path.Combine(locationPath, playerExecutableName);
}
playerExecutableName += string.Format(".{0}", extensionForBuildTarget);

buildOptions.locationPathName = locationPath;
buildOptions.locationPathName = Path.Combine(buildLocation, playerExecutableName);

return new PlayerLauncherBuildOptions
{
BuildPlayerOptions = buildOptions,
PlayerDirectory = Path.Combine(m_TempBuildLocation, playerDirectoryName),
PlayerDirectory = buildLocation,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestRunner.Utils;
using UnityEngine.TestTools.TestRunner;
using UnityEngine.TestTools.TestRunner.Callbacks;

Expand Down Expand Up @@ -37,6 +38,7 @@ public override void Run()
runner.AddEventHandlerMonoBehaviour<PlayModeRunnerCallback>();
runner.AddEventHandlerScriptableObject<TestRunnerCallback>();
runner.AddEventHandlerScriptableObject<CallbacksDelegatorListener>();
runner.AddEventHandlerScriptableObject<TestRunCallbackListener>();
foreach (var eventHandler in m_EventHandlers)
{
Expand Down
12 changes: 12 additions & 0 deletions package/UnityEngine.TestRunner/Utils/ITestRunCallback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using NUnit.Framework.Interfaces;

namespace UnityEngine.TestRunner
{
public interface ITestRunCallback
{
void RunStarted(ITest testsToRun);
void RunFinished(ITestResult testResults);
void TestStarted(ITest test);
void TestFinished(ITestResult result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace UnityEngine.TestTools
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public class PostBuildCleanupAttribute : Attribute
{
public PostBuildCleanupAttribute(Type targetClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace UnityEngine.TestTools
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public class PrebuildSetupAttribute : Attribute
{
public PrebuildSetupAttribute(Type targetClass)
Expand Down
25 changes: 25 additions & 0 deletions package/UnityEngine.TestRunner/Utils/TestRunCallbackAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.CodeDom;

namespace UnityEngine.TestRunner
{
[AttributeUsage(AttributeTargets.Assembly)]
public class TestRunCallbackAttribute : Attribute
{
private Type m_Type;
public TestRunCallbackAttribute(Type type)
{
var interfaceType = typeof(ITestRunCallback);
if (!interfaceType.IsAssignableFrom(type))
{
throw new ArgumentException(string.Format("Type provided to {0} does not implement {1}", this.GetType().Name, interfaceType.Name));
}
m_Type = type;
}

internal ITestRunCallback ConstructCallback()
{
return Activator.CreateInstance(m_Type) as ITestRunCallback;
}
}
}
Loading

0 comments on commit de5fb55

Please sign in to comment.