mirror of
https://github.com/game-ci/unity-test-runner.git
synced 2026-01-29 06:20:07 +08:00
Add standalone testmode support (#219)
* Add standalone support. * Add standalone tests. * UnityStandaloneScripts volume on windows * Update test framework in test project. * Revert IL2CPP setting in test project. Add test for IL2CPP. * Update dist/test-standalone-scripts/Assets/Player/UnityTestRunnerAction/TestRunCallback.cs Co-authored-by: Webber Takken <webber.nl@gmail.com> * Use 2019.2.21f1 * Unity is being dumb, use 2019.4.40f1 for all workflows. * Disable PlayerConnection on build. Print player log. * Add comment about code coverage support in standalone. * Update node-version in test --------- Co-authored-by: Webber Takken <webber.nl@gmail.com>
This commit is contained in:
49
dist/test-standalone-scripts/Assets/Editor/UnityTestRunnerAction/PlayerBuildModifier.cs
vendored
Normal file
49
dist/test-standalone-scripts/Assets/Editor/UnityTestRunnerAction/PlayerBuildModifier.cs
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.TestTools;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityTestRunnerAction;
|
||||
|
||||
[assembly: TestPlayerBuildModifier(typeof(HeadlessPlayModeSetup))]
|
||||
[assembly: PostBuildCleanup(typeof(HeadlessPlayModeSetup))]
|
||||
|
||||
namespace UnityTestRunnerAction
|
||||
{
|
||||
public class HeadlessPlayModeSetup : ITestPlayerBuildModifier, IPostBuildCleanup
|
||||
{
|
||||
private static bool s_RunningPlayerTests;
|
||||
public BuildPlayerOptions ModifyOptions(BuildPlayerOptions playerOptions)
|
||||
{
|
||||
// Do not launch the player after the build completes. Disable the PlayerConnection.
|
||||
playerOptions.options &= ~(BuildOptions.AutoRunPlayer | BuildOptions.ConnectToHost | BuildOptions.WaitForPlayerConnection);
|
||||
|
||||
// Not supporting Mac currently.
|
||||
playerOptions.target = SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? BuildTarget.StandaloneWindows64 : BuildTarget.StandaloneLinux64;
|
||||
|
||||
string[] commandLineArgs = Environment.GetCommandLineArgs();
|
||||
playerOptions.locationPathName = commandLineArgs[Array.IndexOf(commandLineArgs, "-builtTestRunnerPath") + 1]; ;
|
||||
|
||||
// Instruct the cleanup to exit the Editor if the run came from the command line.
|
||||
// The variable is static because the cleanup is being invoked in a new instance of the class.
|
||||
s_RunningPlayerTests = true;
|
||||
return playerOptions;
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
if (s_RunningPlayerTests && IsRunningTestsFromCommandLine())
|
||||
{
|
||||
// Exit the Editor on the next update, allowing for other PostBuildCleanup steps to run.
|
||||
EditorApplication.update += () => { EditorApplication.Exit(0); };
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsRunningTestsFromCommandLine()
|
||||
{
|
||||
var commandLineArgs = Environment.GetCommandLineArgs();
|
||||
return commandLineArgs.Any(value => value == "-runTests");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user