Get Started

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

Note

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

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 Altom website.

  1. Download from Altom website - link.

  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.0.1" to your project manifest.json, inside dependencies.

{
    "dependencies": {
        "com.unity.nuget.newtonsoft-json": "3.0.1"
    }
}
  • 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"
  ]
}

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 game 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 game or “Build & Run” to start your instrumented game 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

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 game 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.

Run your game 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 regular and custom input by toggling the box with the Custom Input label. Take into consideration that if you are using the New Input System, then after activating the custom 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 game

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 game. 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 game.

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. 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 Altom.AltDriver;

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 running your tests, start the instrumented game and wait for popup with the message: Waiting for connection on port: 13000.