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.
Download from Altom website - link.
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.
Instrument your game with AltTester Unity SDK
Steps:
Open the AltTester Editor window from Unity Editor -> AltTester -> AltTester Editor
In the Build Settings section set AltTester Port to 13000
In the Scene Manager section select the scenes you want to include in your build
In the Platform section select desired platform and set the path to where you want to save the build
Press “Build Only” to instrument the game or “Build & Run” to start your instrumented game after the build succeeded
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.
Open AltTester Editor
In platform section select Editor
Click Play in Editor
Open AltTester Editor
In platform section select Standalone
Choose your build target
Click Build & Run
Important
Make sure to set the “Api Compatibility Level” to “.NET 4.x” in Unity versions lower than 2021 when building using the Standalone option.
This setting can be found under Edit menu -> Project Settings -> Player -> Other Settings -> Configuration.
Prerequisites:
Use the Unity Hub to install Android Build Support and the required dependencies: Android SDK & NDK tools, and OpenJDK
Steps:
Open AltTester Editor
In platform section select Android
Click Build & Run
Prerequisites:
Have IProxy installed:
brew install libimobiledevice
Steps:
Open AltTester Editor
In platform section select iOS
Click Build & Run
Note
Check the following link to see how to build and run your game for iOS (.ipa file) – link.
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.
Create a folder named Editor in your Unity Project.
Right-click on Editor folder and select Create -> AltTest. This will create a template file in which you could start to write your test.
Name the file MyFirstTest.
Open AltTester Editor.
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);
}
}
using NUnit.Framework;
using Altom.AltDriver;
public class MyFirstTest
{
private AltDriver altDriver;
[OneTimeSetUp]
public void SetUp()
{
AltPortForwarding.ForwardAndroid();
altDriver = new AltDriver();
}
[OneTimeTearDown]
public void TearDown()
{
altDriver.Stop();
AltPortForwarding.RemoveForwardAndroid();
}
[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);
}
}
using NUnit.Framework;
using Altom.AltDriver;
public class MyFirstTest
{
private AltDriver altDriver;
[OneTimeSetUp]
public void SetUp()
{
AltPortForwarding.ForwardIos();
altDriver = new AltDriver();
}
[OneTimeTearDown]
public void TearDown()
{
altDriver.Stop();
AltPortForwarding.KillAllIproxyProcess();
}
[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
AltTester-Driver for C# is available also as a nuget package. You can use the nuget package to write your tests in a separate tests project, independent of the Unity application.
Create a new test project
mkdir <test-project-name>
cd <test-project-name>
dotnet new nunit
Install AltTester-Driver nuget package
dotnet add package AltTester-Driver --version 1.8.2
Run your tests
dotnet test
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);
}
}
using NUnit.Framework;
using Altom.AltDriver;
public class MyFirstTest
{
private AltDriver altDriver;
[OneTimeSetUp]
public void SetUp()
{
AltPortForwarding.ForwardAndroid();
altDriver = new AltDriver();
}
[OneTimeTearDown]
public void TearDown()
{
altDriver.Stop();
AltPortForwarding.RemoveForwardAndroid();
}
[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);
}
}
using NUnit.Framework;
using Altom.AltDriver;
public class MyFirstTest
{
private AltDriver altDriver;
[OneTimeSetUp]
public void SetUp()
{
AltPortForwarding.ForwardIos();
altDriver = new AltDriver();
}
[OneTimeTearDown]
public void TearDown()
{
altDriver.Stop();
AltPortForwarding.KillAllIproxyProcess();
}
[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);
}
}
AltTester-Driver for Java is available as a maven package or as a standalone jar. Use one of the following methods to import the driver in your tests project.
Method 1: Add AltTester-Driver for Java as a dependency in your
pom.xml
file:<dependency> <groupId>com.alttester</groupId> <artifactId>alttester</artifactId> <version>1.8.2</version> </dependency>Method 2: Use the
.jar
file from GIT (without building it from source)
Download AltTester-Driver for Java.
Install the
.jar
file:mvn install:install-file -Dfile=./target/AltTester-Driver.jar -DgroupId=com.alttester -DartifactId=alttester -Dversion=1.8.2 -Dpackaging=jar
Run your tests by using the following command (in the test project folder):
mvn test
Example test file:
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import com.alttester.AltDriver;
import com.alttester.AltObject;
import com.alttester.Commands.FindObject.AltFindObjectsParameters;
import com.alttester.Commands.FindObject.AltWaitForObjectsParameters;
import java.io.IOException;
public class myFirstTest {
private static AltDriver altDriver;
@BeforeClass
public static void setUp() throws IOException {
altDriver = new AltDriver();
}
@AfterClass
public static void tearDown() throws Exception {
altDriver.stop();
}
@Test
public void openClosePanelTest() {
altDriver.loadScene("Scene 2 Draggable Panel");
AltFindObjectsParameters altFindObjectsParametersCamera = new AltFindObjectsParameters.Builder(
AltDriver.By.PATH, "//Main Camera")
.build();
AltObject camera = altDriver.findObject(altFindObjectsParametersCamera);
AltFindObjectsParameters closeButtonObjectsParameters = new AltFindObjectsParameters.Builder(
AltDriver.By.NAME, "Close Button")
.withCamera(AltDriver.By.ID, String.valueOf(camera.id))
.build();
altDriver.findObject(closeButtonObjectsParameters).tap();
AltFindObjectsParameters buttonObjectsParameters = new AltFindObjectsParameters.Builder(
AltDriver.By.NAME, "Button")
.withCamera(AltDriver.By.ID, String.valueOf(camera.id))
.build();
altDriver.findObject(buttonObjectsParameters).tap();
AltFindObjectsParameters panelObjectsParameters = new AltFindObjectsParameters.Builder(
AltDriver.By.NAME, "Panel")
.withCamera(AltDriver.By.ID, String.valueOf(camera.id))
.build();
AltWaitForObjectsParameters panelWaitForObjectsParameters = new AltWaitForObjectsParameters.Builder(
panelObjectsParameters).build();
AltObject panelElement = altDriver.waitForObject(panelWaitForObjectsParameters);
Assert.assertTrue(panelElement.isEnabled());
}
}
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import com.alttester.AltPortForwarding;
import com.alttester.AltDriver;
import com.alttester.AltObject;
import com.alttester.Commands.FindObject.AltFindObjectsParameters;
import com.alttester.Commands.FindObject.AltWaitForObjectsParameters;
import java.io.IOException;
public class myFirstTest {
private static AltDriver altDriver;
@BeforeClass
public static void setUp() throws IOException {
AltPortForwarding.forwardAndroid();
altDriver = new AltDriver();
}
@AfterClass
public static void tearDown() throws Exception {
altDriver.stop();
AltPortForwarding.removeForwardAndroid();
}
@Test
public void openClosePanelTest() {
altDriver.loadScene("Scene 2 Draggable Panel");
AltFindObjectsParameters altFindObjectsParametersCamera = new AltFindObjectsParameters.Builder(
AltDriver.By.PATH, "//Main Camera")
.build();
AltObject camera = altDriver.findObject(altFindObjectsParametersCamera);
AltFindObjectsParameters closeButtonObjectsParameters = new AltFindObjectsParameters.Builder(
AltDriver.By.NAME, "Close Button")
.withCamera(AltDriver.By.ID, String.valueOf(camera.id))
.build();
altDriver.findObject(closeButtonObjectsParameters).tap();
AltFindObjectsParameters buttonObjectsParameters = new AltFindObjectsParameters.Builder(
AltDriver.By.NAME, "Button")
.withCamera(AltDriver.By.ID, String.valueOf(camera.id))
.build();
altDriver.findObject(buttonObjectsParameters).tap();
AltFindObjectsParameters panelObjectsParameters = new AltFindObjectsParameters.Builder(
AltDriver.By.NAME, "Panel")
.withCamera(AltDriver.By.ID, String.valueOf(camera.id))
.build();
AltWaitForObjectsParameters panelWaitForObjectsParameters = new AltWaitForObjectsParameters.Builder(
panelObjectsParameters).build();
AltObject panelElement = altDriver.waitForObject(panelWaitForObjectsParameters);
Assert.assertTrue(panelElement.isEnabled());
}
}
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import com.alttester.AltPortForwarding;
import com.alttester.AltDriver;
import com.alttester.AltObject;
import com.alttester.Commands.FindObject.AltFindObjectsParameters;
import com.alttester.Commands.FindObject.AltWaitForObjectsParameters;
import java.io.IOException;
public class myFirstTest {
private static AltDriver altDriver;
@BeforeClass
public static void setUp() throws IOException {
AltPortForwarding.forwardIos();
altDriver = new AltDriver();
}
@AfterClass
public static void tearDown() throws Exception {
altDriver.stop();
AltPortForwarding.killAllIproxyProcess();
}
@Test
public void openClosePanelTest() {
altDriver.loadScene("Scene 2 Draggable Panel");
AltFindObjectsParameters altFindObjectsParametersCamera = new AltFindObjectsParameters.Builder(
AltDriver.By.PATH, "//Main Camera")
.build();
AltObject camera = altDriver.findObject(altFindObjectsParametersCamera);
AltFindObjectsParameters closeButtonObjectsParameters = new AltFindObjectsParameters.Builder(
AltDriver.By.NAME, "Close Button")
.withCamera(AltDriver.By.ID, String.valueOf(camera.id))
.build();
altDriver.findObject(closeButtonObjectsParameters).tap();
AltFindObjectsParameters buttonObjectsParameters = new AltFindObjectsParameters.Builder(
AltDriver.By.NAME, "Button")
.withCamera(AltDriver.By.ID, String.valueOf(camera.id))
.build();
altDriver.findObject(buttonObjectsParameters).tap();
AltFindObjectsParameters panelObjectsParameters = new AltFindObjectsParameters.Builder(
AltDriver.By.NAME, "Panel")
.withCamera(AltDriver.By.ID, String.valueOf(camera.id))
.build();
AltWaitForObjectsParameters panelWaitForObjectsParameters = new AltWaitForObjectsParameters.Builder(
panelObjectsParameters).build();
AltObject panelElement = altDriver.waitForObject(panelWaitForObjectsParameters);
Assert.assertTrue(panelElement.isEnabled());
}
}
There are two methods of installing the AltTester-Driver for Python package:
Method 1: Installing using Pip:
pip install AltTester-Driver
Method 2: Install from the source code in the repository:
git clone git@github.com:alttester/AltTester-Unity-SDK.git cd alttester/Bindings~/python python setup.py install
Run your test file using the unittest
module:
python -m unittest <name_of_your_test_file.py>
Run your test file using the pytest
package:
pytest <name_of_your_test_file.py>
Example test file:
import unittest
from alttester import *
class MyFirstTest(unittest.TestCase):
altdriver = None
@classmethod
def setUpClass(cls):
cls.altdriver = AltDriver()
@classmethod
def tearDownClass(cls):
cls.altdriver.stop()
def test_open_close_panel(self):
self.altdriver.load_scene('Scene 2 Draggable Panel')
self.altdriver.find_object(By.NAME, "Close Button").tap()
self.altdriver.find_object(By.NAME, "Button").tap()
panel_element = self.altdriver.wait_for_object(By.NAME, "Panel")
self.assertTrue(panel_element.enabled)
import unittest
from alttester import *
class MyFirstTest(unittest.TestCase):
altdriver = None
@classmethod
def setUpClass(cls):
AltPortForwarding.forward_android()
cls.altdriver = AltDriver()
@classmethod
def tearDownClass(cls):
cls.altdriver.stop()
AltPortForwarding.remove_forward_android()
def test_open_close_panel(self):
self.altdriver.load_scene("Scene 2 Draggable Panel")
self.altdriver.find_object(By.NAME, "Close Button").tap()
self.altdriver.find_object(By.NAME, "Button").tap()
panel_element = self.altdriver.wait_for_object(By.NAME, "Panel")
self.assertTrue(panel_element.enabled)
import unittest
from alttester import *
class MyFirstTest(unittest.TestCase):
altdriver = None
@classmethod
def setUpClass(cls):
AltPortForwarding.forward_ios()
cls.altdriver = AltDriver()
@classmethod
def tearDownClass(cls):
cls.altdriver.stop()
AltPortForwarding.kill_all_iproxy_process()
def test_open_close_panel(self):
self.altdriver.load_scene("Scene 2 Draggable Panel")
self.altdriver.find_object(By.NAME, "Close Button").tap()
self.altdriver.find_object(By.NAME, "Button").tap()
panel_element = self.altdriver.wait_for_object(By.NAME, "Panel")
self.assertTrue(panel_element.enabled)
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.