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.

Get AltUnity Pro Alpha license

To be able to use AltUnity Pro Alpha, the first step is to get a trial license. You can use the alpha version for free for a period of 30 days. If you need our app for a longer period of time, you can contact us to extend the number of days. Then download AltUnity Pro Alpha package

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

AltUnity Tester Unity Package also includes the AltUnity Driver along with its bindings in C#, Python, and Java, meaning that you can also write your tests in Python or Java if C# is not your preferred language.

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

Instrument your game with AltUnity Tester Alpha

In order to run automated tests using AltUnity Pro Alpha, you first have to instrument your game with the AltUnity Tester asset. This will enable a connection with your game, to get information about the Unity objects.

To instrument your game with AltUnity Tester, you first have to open the AltUnity Tester Editor window mentioned in the previous section and follow the steps below to build your game:

Steps:

  1. In the Build Settings section set the Proxy host to the IP/hostname of the device where the AltUnity Pro desktop app (including the Proxy) is running. Set the Proxy port to another available port if 13000 is in use on your machine. You can also leave the default values for the host or the port.

  2. In the Scene Manager section select the scenes you want to include in your build. In the Platform section select the desired platform (WebGL in our case) and set the path to where you want to save the build.

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

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

webgl

Note

Open the WebGL player settings and go to the Resolution and Presentation section. Check the Run In Background Setting. This setting allows you to run the game in the background, which is necessary when using AltUnity Pro Alpha.

Note

Enable the exceptions in the Publishing Settings area.

exceptions

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.

Run your game on WebGL

In order to run the tests, you need to have the WebGL build opened.

If you choose the “Build & Run” option, mentioned in the previous section, then you can skip this step as Unity itself will run as a small webserver to host your game.

Otherwise, if you choose the “Build” option you will need a webserver to host your game. You can run a game locally by following the next steps:

  • Make sure you have node.js installed.

  • Type in the command line the following command npm install -g http-server.

  • Go to the build folder location and in the command line write http-server.

  • From the console, take the provided address to open the game build in browser.

After you follow all the steps provided above, you should have the WebGL game instrumented with AltUnity Tester opened in the browser. The green pop-up tells us the current version of AltUnity Tester along with the Proxy host and port. It also shows us that the game is not connected yet to the Proxy Module but it’s waiting for the Proxy to be available.

instrumented

Start the Proxy Module (Connect your game to AltUnity Pro Alpha)

After creating a test build instrumented with AltUnity Tester, you need to start AltUnity Pro Alpha. This application contains a Proxy Module that allows the game and the tests to communicate with each other via an IP address or hostname. This connection is necessary because it acts as a websocket server that facilitates the communication between the tests and the instrumented Unity app. Your tests won’t be able to run until this connection is enabled.

In order to start the Proxy Module, you have to start in AltUnity Pro Alpha the connection to your game build. To do so, you have to type in the Proxy port that you set in the Instrument your game with AltUnity Tester Alpha section.

startProxy

Write and run the 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.

If you’re not familiar with the source code of the game you are about to test, inspecting the elements in AltUnity Pro Alpha should be very helpful to you. You might find it easier to see the exact fields or properties of an object in the Element Information Panel than in the Inspector window in Unity Editor. You can also copy the path of an object to use it in finding the object in the scene in a test.

inspect

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.