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.

Note

From version 1.7.0 on we’ll be referring to AltUnity Server as AltUnity Tester.

Import AltUnity Tester package in Unity Editor

To instrument your Unity application with AltUnity Tester you first need to import the AltUnity Tester package into Unity. This can be done either by downloading from the Unity Asset Store or from the GitLab pages.

  1. Download from Unity Asset Store - link.

  2. Go to your Asset Store Downloads Manager from Unity Editor.

  3. Import the package into your Unity project.

Resolve dependencies

  • Newtonsoft.Json

In order for AltUnity Tester 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

AltUnity Tester has support for Input System starting with version 1.7.1. To enable Input System in AltUnity Tester 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 AltUnity Tester Editor window from Unity Editor -> AltUnity Tools -> AltUnity Tester Editor.

Window menu with AltUnity Tester Options

Instrument your game with AltUnity Tester

Steps:

  1. Open AltUnity Tester Editor window from Unity Editor -> AltUnity Tools -> AltUnity Tester Editor

  1. In the Build Settings section set AltUnity Tester Port to 13000

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

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

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

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

Important

AltUnity Tester 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 AltUnity Tester.

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 :ref:`<pages/advanced-usage:Build games from the command line>.

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 AltUnity Tester Editor

  2. In platform section select Editor

  3. Click Play in Editor

Write and execute first test for your game

To write tests with AltUnity Tester you need to import the AltUnity Driver in your tests project.

AltUnity Tester package contains AltUnityDriver 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.

AltUnity C# Driver is already included in AltUnity Tester 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 -> AltUnityTest. This will create a template file in which you could start to write your test.

  3. Name the file MyFirstTest.

  4. Open AltUnity Tester 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.AltUnityDriver;

public class MyFirstTest
{
  private AltUnityDriver altUnityDriver;

  [OneTimeSetUp]
  public void SetUp()
  {
    altUnityDriver = new AltUnityDriver();
  }

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

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

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

    var panelElement = altUnityDriver.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 AltUnityTestRunner.RunTestFromCommandLine -tests MyFirstTest.TestStartGame -logFile logFile.log -batchmode -quit

Now your project can use all the AltUnity Driver Commands.

Note

Before running your tests, start the instrumented game and wait for popup with the message: Waiting for connection on port: 13000.