Get Started

To run the first test for your Unity app you need to:

Note

If you don’t have access to source code of the app you need to ask a person with access to give you an instrumented version of the app.

Import AltTester® package in Unity Editor

To instrument your Unity application with AltTester® Unity SDK you first need to import the AltTester® package into Unity. This can be done either by downloading from the AltTester® website, or by following the steps from the OpenUPM website.

  1. Download from AltTester®.

  2. Import it by drag and drop inside your Unity project.

Resolve dependencies

  • Newtonsoft.Json

In order for AltTester® Unity SDK to work you need dependency for Newtonsoft.Json. Add "com.unity.nuget.newtonsoft-json": "3.1.0" to your project manifest.json, inside dependencies.

{
    "dependencies": {
        "com.unity.nuget.newtonsoft-json": "3.1.0"
    }
}
  • Input System

AltTester® Unity SDK has support for Input System starting with version 1.7.1. To enable Input System in AltTester® Unity SDK you need to add "com.unity.inputsystem" to your manifest.json, inside testables.

{
    "testables": ["com.unity.inputsystem"]
}
  • Editor Coroutines

In order for AltTester® Unity SDK to work with your project you need the dependency for Editor Coroutines. Add "com.unity.editorcoroutines": "1.0.0 to your project manifest.json, inside dependencies.

{
    "dependencies": {
        "com.unity.editorcoroutines": "1.0.0"
    }
}

Important

To make sure the import was correct, check if you can open the AltTester® Editor window from Unity Editor -> AltTester® -> AltTester® Editor.

Window menu with AltTester® Unity SDK Options

Instrument your app with AltTester® Unity SDK

Steps:

  1. Open the AltTester® Editor window from Unity Editor -> AltTester® -> AltTester® Editor

  2. In the Build Settings section set AltTester® Port to 13000

  3. In the Scene Manager section select the scenes you want to include in your build

  4. In the Platform section select desired platform and set the path to where you want to save the build

  5. Press “Build Only” to instrument the app or “Build & Run” to start your instrumented app after the build succeeded

  6. Check the console to see if the build was successful.

Important

AltTester® Unity SDK is intended to be used only in debug builds, and it will not work in release mode out of the box. You need to make sure you don’t release a production build instrumented with AltTester® Unity SDK.

Note

If you want to build your intrumented app from outside the AltTester® Editor window you will have to make sure to uncheck the Development Build setting from the Build Settings menu in Unity (go to File -> Build Settings) after selecting your Scenes, as seen bellow.

Build Settings menu from Unity

Note

Your build files are available in the configured Output path. By default, the Output path is a folder with the same name as your game.

Note

If you have a custom build, check how you can build from the command line using the instructions in the Advanced Usage section.

Note

If changes are made inside a test, rebuilding the application is not necessary. A rebuild is needed only if changes are made inside the Unity project.

Note

To be able to run your instrumented app in the background, go to File -> Build Settings -> Player Settings -> Project Settings -> Player -> Resolution and presentation and check the box next to Run in background.

Note

To make sure you can catch possible exceptions thrown from your tests, you’ll have to go to Edit -> Project Settings -> Player -> Publishing Settings and set Enable Exceptions to Full With Stacktrace.

Note

When running the WebGL build of your app in browser, even with the Run in background setting enabled, you still might experience slow performance if the tab with your content is not on focus. Make sure that the tab with your app is visible, otherwise your content will only update once per second in most browsers.

Start the AltTester® Server Module

The AltTester® Server Module is incorporated in AltTester® Desktop. In order to start it, all you have to do is to open AltTester® Desktop.

Run your app in Unity or on desired platform

Before running your tests you need to start the instrumented Unity application. Upon startup, your instrumented Unity app should display a popup with the message: “Waiting for connections on port: {Port}”. The popup disappears when your app has successfully connected to the tests.

  1. Open AltTester® Editor

  2. In platform section select Editor

  3. Click Play in Editor

Note

You can switch between the regular and the AltTester® input by toggling the box with the AltTester® Input label. Take into consideration that if you are using the New Input System, then after activating the AltTester® input, you will only be able to interact with the instrumented build via your automated tests or the AltTester® Desktop.

Write and execute first test for your app

To write tests with AltTester® Unity SDK you need to import the AltDriver in your tests project.

AltTester® package contains AltDriver class used to connect to the instrumented app. In the setup method create an instance of the driver and in the tear-down method invoke the stop method of the driver. With the instance of the driver you can query the Unity objects and interact with the app.

AltTester-Driver for C# is already included in AltTester® package. If you are writing tests in C# then you can create your tests directly from Unity.

  1. Create a folder named Editor in your Unity Project.

  2. Right-click on Editor folder and select Create -> AltTest. This will create a template file in which you could start to write your test.

  3. Name the file MyFirstTest.

  4. Open AltTester® Editor.

  5. Make sure that the AltTester® Desktop app is running (Starting with version 2.0.0, AltTester® Desktop must be running on your PC while the tests are running).

  6. In the Run Tests section press “Run All Tests” button. You should see the output of the tests in Unity Editor Console

Example test file:

using NUnit.Framework;
using AltTester.AltTesterUnitySDK.Driver;

public class MyFirstTest
{
    private AltDriver altDriver;

    [OneTimeSetUp]
    public void SetUp()
    {
        altDriver = new AltDriver();
    }

    [OneTimeTearDown]
    public void TearDown()
    {
        altDriver.Stop();
    }

    [Test]
    public void TestStartGame()
    {
        altDriver.LoadScene("Scene 2 Draggable Panel");

        altDriver.FindObject(By.NAME, "Close Button").Tap();
        altDriver.FindObject(By.NAME, "Button").Tap();

        var panelElement = altDriver.WaitForObject(By.NAME, "Panel");
        Assert.IsTrue(panelElement.enabled);
    }
}

Run your test file from the command line by using the following command:

<UnityPath>/Unity -projectPath $PROJECT_DIR -executeMethod AltTestRunner.RunTestFromCommandLine -tests MyFirstTest.TestStartGame -logFile logFile.log -batchmode -quit

Now your project can use all the AltDriver Commands.

Note

Before the connection step, start the instrumented app and wait for the green popup with the message: Waiting to connect to AltTester® Server on IP:port with app name: ‘your app name’.