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 Unity application with AltUnity Tester you first need to import the AltUnity Tester package into Unity.

  1. Download AltUnity Tester Alpha.

  2. Import it by drag and drop inside 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 Tester Alpha

Steps:

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

  2. In the Build Settings section set the Proxy host to the IP/hostname of the device where the Proxy is running. Set the Proxy port to the port configured in the Proxy.

  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.

webgl

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

Note

When running the WebGL build of your game 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 Proxy Module

The Proxy Module is incorporated in AltUnity Pro Alpha. In order to start it, all you have to do is to start AltUnity Pro Alpha.

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: “Connecting to AltUnity Proxy on {ProxyHost}:{ProxyPort}”. The popup disappears when your app has successfully connected to the proxy.

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

Note

Before running your tests, start the Proxy and the Instrumented Unity app.