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 AltUnity Tester package in Unity Editor

To instrument your game with AltUnity Server 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.

Important

To make sure the import was correct, check if you can open AltUnity Tester Editor Window from Unity Editor -> AltUnity Tools -> AltUnityTester.

window menu with altUnity Tester

Instrument your game with AltUnity Server

In order for the tests to have access to Unity objects via AltUnity Client you need to instrument the game with AltUnity Server.

Steps:

  1. Open AltUnity Tester Window from Unity Editor -> AltUnity Tools -> AltUnityTester.

  2. Select Scenes in Build

  3. Select on what platform you want to build the game.

  4. Press “Build Only” to instrument the game.

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

Important

Make sure to set the “Api Compatibility Level” to “.NET 4.x” in Unity when building using the Standalone option.

This setting can be found under Edit menu -> Project Settings -> Player -> Other Settings -> Configuration.

Important

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

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.

Run your game in Unity or on desired platform

Before running your tests you need to start the game instrumented with AltUnity Server. Upon startup, your game should display a popup with the message: “waiting for connection on port 13000”.

  1. Open AltUnity Tester Window

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

Note

Example tests below are setup to run on Scene 2 and Scene 3 from the Example folder under the AltUnity Tester package.

If you want to use these examples for other scenes / games, make sure to update the test accordingly.

AltUnity C# Client 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 Window.

  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 Client Commands.

Note

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