Write your first test#

On this page you write a test that opens a scene in your app and interacts with its objects. Choose your language in any of the tabs below: the others switch with it.

Before you start#

  • AltTester® Desktop is running. It starts AltTester® Server, which your app and your tests connect to. See Start the AltTester® Server.

  • Your instrumented app is running and connected. The green AltTester® pop-up in the app first shows Waiting to connect to AltTester® Server on IP:port with app name: 'your app name', then Connected to AltTester® Server…. If the app runs on another device, enter the IP of the machine where AltTester® Desktop runs in the pop-up and press Restart. See Connecting to the server.

  • The tools for your language: .NET for C#, Java, Python, or Robot Framework. C# tests can also run inside the Unity Editor, with nothing else to install.

1. Set up a test project#

Create an NUnit project in an empty folder, and add the AltTester® driver to it:

dotnet new nunit
dotnet add package AltTester-Driver --version x.y.z

x.y.z is the driver version; see Compatibility for the versions that work with your AltTester® Unity SDK.

2. Write the test#

The test connects to AltTester® Server when it starts, and stops the driver when it ends. In between it loads a scene and works with its objects: it finds them, taps or drags them, and checks the result.

using NUnit.Framework;
using AltTester.AltTesterSDK.Driver;

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);
    }
}

On Android#

An app on an Android device connected by USB reaches AltTester® Server through reverse port forwarding. The test sets it up before it connects and removes it at the end. See Reverse port forwarding for the same test with those lines added, in every language.

On iOS#

The test doesn’t change. Enter the IP of the machine where AltTester® Server runs in the app’s pop-up, as described in Connecting to the server.

3. Run the test#

In the project folder, run:

dotnet test

Next steps#