Skip to content
Tim Rademaker edited this page Jun 14, 2022 · 8 revisions

Initialization

init

Set up the Unity base directory, so that Unity can be used in the other functions.

Parameters

unityDir: The directory Unity is located in.

Example

unity.init('C:/Program Files/Unity/Hub/Editor/2019.2.17f1');

Executing Editor Methods

execute

Executes a method from an editor script. This can be used to, for example, build a project.

Parameters

projectDir: The directory the project is in.

methodToExecute: The method to execute. This follows the convention of [Namespace.]ClassName.FunctionName, where FunctionName is a public static member function of ClassName.

buildTarget (optional): The build target for this project. Possible options are: Standalone, Win, Win64, OSXUniversal, Linux64, iOS, Android, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, tvOS.

logFile (optional): The file to log Unity's build output to. Defaults to ${env.WORKSPACE}/logs/UnityLog-${env.BUILD_NUMBER}.txt if not specified.

noGraphics (optional): If set to true, no graphics device is initialized. This allows Unity to run on devices without a GPU, but prevents Enlighten from baking GI (as this requires GPU acceleration).

additionalParameters (optional): Additional command line arguments to pass to Unity.

outputLogOnFailure (optional): If true, the log file is printed to the console if Unity exits with a non-zero exit code. Defaults to true.

Example

unity.execute('C:/Unity Workspace/ExampleProject', 'BuildScripts.BuildGame');

unity.execute('C:/Unity Workspace/ExampleProject', 'BuildScripts.BuildGame', 'PS4', '', true, '-noUpm -force-free');

A simple BuildGame-function could look as follows:

public class BuildScripts
{
    public static void BuildGame()
    {
        BuildPlayerOptions options = new BuildPlayerOptions();
        // Set options here
        BuildPipeline.BuildPlayer(options);
    }
}

Running Tests

runTests

Run automation tests for a project. If any of the tests fail, the build will be marked as unstable.

Parameters

projectDir: The directory the project is in.

testPlatform (optional): The platform you want to run the tests on. Defaults to Editor Mode.

testFilters (optional): A list of test names to run, or a regular expression pattern to match tests by their full name. Negation can also be used here; !MyNamespace.Something.MyTest would run all tests except that test. When left empty, all tests are run. Using this in combination with testCategories will result in only tests matching both being run.

testCategories (optional): A list of test categories to run. Negation can also be used here; !MyTestCategory would exclude all tests from that category to be excluded from the run. Using this in combination with testFilters will result in only tests matching both being run.

testSettingsFile (optional): A test settings file used to set extra options for tests.

testResultFile (optional): The (xml) file to output test results in. If left empty, the test results will be placed in ${env.WORKSPACE}/logs/UnityTestLog-${env.BUILD_NUMBER}.xml.

noGraphics (optional): If set to true, no graphics device is initialized. This allows Unity to run on devices without a GPU.

Example

unity.runTests('C:/Unity Workspace/ExampleProject');

unity.runTests('C:/Unity Workspace/ExampleProject', 'Android', '', 'SmokeTests', "${env.WORKSPACE}/Game/testSettings.json");

Clone this wiki locally