using System; using UnityEditor; using UnityEditor.TestRunner.CommandLineParser; using UnityEditor.TestTools.TestRunner.Api; using UnityEngine; namespace Unity.PerformanceTesting.Editor { [InitializeOnLoad] class TestRunnerInitializer { static TestRunnerInitializer() { var args = GetCmdLineArguments(); var resultsHandler = args.IsCmdLineRun && !string.IsNullOrEmpty(args.PerfTestResults) ? CreateCmdLineResultsHandler(args) : ScriptableObject.CreateInstance(); var api = ScriptableObject.CreateInstance(); api.RegisterCallbacks(resultsHandler); } static ICallbacks CreateCmdLineResultsHandler(CmdLineArguments cmdLineArguments) { var callbacks = ScriptableObject.CreateInstance(); callbacks.SetResultsLocation(cmdLineArguments.PerfTestResults); return callbacks; } static CmdLineArguments GetCmdLineArguments() { var isCmdLineTestRun = false; string resultFilePath = null; var optionSet = new CommandLineOptionSet( new CommandLineOption("runTests", () => { isCmdLineTestRun = true; }), new CommandLineOption("runEditorTests", () => { isCmdLineTestRun = true; }), new CommandLineOption("perfTestResults", filePath => { resultFilePath = filePath; }) ); optionSet.Parse(Environment.GetCommandLineArgs()); return new CmdLineArguments(isCmdLineTestRun, resultFilePath); } class CmdLineArguments { public bool IsCmdLineRun; public string PerfTestResults; public CmdLineArguments(bool isCmdLineRun, string perfTestResults) { IsCmdLineRun = isCmdLineRun; PerfTestResults = perfTestResults; } } } }