This is a beginner-friendly test automation project for Unity games using AltTester. If you're new to automated testing, don't worry! This guide will walk you through everything step-by-step.
What you'll learn:
- How to automatically test your Unity game (no manual clicking!)
- How to find and interact with game objects programmatically
- How to verify your game works correctly across different scenarios
The fastest way to get started:
- Make sure your Unity game is running with AltTester already connected
- Run the test script:
- macOS/Linux:
./run_tests.sh - Windows:
run_tests.bat
- macOS/Linux:
- Watch the magic happen! ✨
The template includes example tests that you can adapt for any game!
Before we begin, you need:
- A Unity game with AltTester integrated (this should already be done by your development team)
- AltTester Desktop app - Download from altom.com/alttester
- .NET 8.0 SDK - Download from microsoft.com/net
- Download and install AltTester Desktop
- Launch AltTester Desktop
- Start your Unity game (the one with AltTester integration)
- Verify connection: You should see your game appear in AltTester Desktop
- Download/clone this project to your computer
- Open a terminal/command prompt in the project folder
- Install dependencies:
dotnet restore
- Build the project:
dotnet build
Option A: Use the Simple Scripts (Recommended for beginners)
- macOS/Linux:
./run_tests.sh
- Windows:
run_tests.bat
Option B: Use dotnet CLI (More control)
dotnet test --logger "console;verbosity=detailed"🎉 Congratulations! You just ran your first automated test!
- View Object Model: Clean separation of test logic and view interactions
- Multi-Driver Support: AltTester, Appium (mobile), and Selenium (web) integration
- Two Template Views: Main menu and gameplay view objects to get you started quickly
- Comprehensive Examples: Template code covering common game testing scenarios
- NUnit Framework: Industry-standard testing framework for .NET
- Configuration Management: Environment-based configuration with sensible defaults
- Utility Classes: Common helpers for locators, reporting, and driver management
- Easy Customization: Template code with clear instructions for adaptation
AltTesterProject/
├── Common/ # Shared utilities and infrastructure
│ ├── DriverContainer.cs # Multi-driver container
│ ├── Reporter.cs # Test reporting utilities
│ └── TestConfiguration.cs # Configuration management
├── Views/ # View Object Model classes
│ ├── BaseView.cs # Base view with common functionality
│ ├── MainMenuView.cs # Main menu view object
│ └── GamePlayView.cs # Game play view object
├── Tests/ # Test classes
│ ├── BaseTest.cs # Base test class with setup/teardown
│ └── MainMenuTests.cs # Main menu tests
├── run_tests.sh # Simple test runner for Linux/macOS
├── run_tests.bat # Simple test runner for Windows
└── GlobalUsings.cs # Global using statements
This is the simplest way to get started. Your Unity game runs on the same computer as your tests.
Requirements:
- Unity game with AltTester integration running locally
- AltTester Desktop app connected to your game
How to run:
# macOS/Linux
./run_tests.sh
# Windows
run_tests.batUse this when you want to test your game on mobile devices (Android/iOS).
Additional Requirements:
- Appium Server installed and running
- Android SDK/Xcode (depending on platform)
- Physical device or emulator connected
Setup Appium (if you're new to this):
-
Install Appium:
npm install -g appium
-
Start Appium Server:
appium
-
Run tests with Appium:
# macOS/Linux RUN_TESTS_WITH_APPIUM=true ./run_tests.sh # Windows set RUN_TESTS_WITH_APPIUM=true && run_tests.bat
Use this when your game is deployed as WebGL and runs in a browser.
Additional Requirements:
- Chrome browser installed
- ChromeDriver (automatically managed)
Run WebGL tests:
# macOS/Linux
TEST_PLATFORM=WebGL RUN_TESTS_WITH_SELENIUM=true ./run_tests.sh
# Windows
set TEST_PLATFORM=WebGL && set RUN_TESTS_WITH_SELENIUM=true && run_tests.batThink of Views as representatives of your game screens. Instead of manually clicking buttons, Views do it programmatically.
Example: MainMenuView.cs represents your game's main menu and can:
- Click the "Play" button
- Check if the menu loaded correctly
- Navigate to other screens
Tests are instructions that tell the computer how to verify your game works correctly.
Example: A test might:
- Start the game
- Check if the main menu appears
- Click "Play"
- Verify the game starts correctly
AltTesterProject/
├── Views/ # 🎭 Game screen representatives
│ ├── MainMenuView.cs # - Handles main menu interactions
│ └── GamePlayView.cs # - Handles gameplay interactions
├── Tests/ # 🧪 Test instructions
│ └── MainMenuTests.cs # - Tests for main menu
├── Common/ # 🔧 Shared utilities
└── run_tests.sh/.bat # 🚀 Simple test runners
- Open
Views/MainMenuView.cs - Find this section:
private readonly (By, string) PlayButton = (By.NAME, "PlayButtonName");
- Replace
"PlayButtonName"with your actual button name from Unity - Repeat for other elements
- Open
Tests/MainMenuTests.cs - Add a new test method:
[Test] public void TestMyGameFeature() { // Your test steps here Reporter.Log("Testing my awesome feature"); // Add assertions to verify behavior }
Problem: AltTester can't connect to your game Solution:
- Make sure your Unity game is running
- Check that AltTester Desktop shows your game as connected
- Verify the game has AltTester integration
Problem: Test can't find a button or game object Solution:
- Check the exact name of your game object in Unity
- Update the locator in your View class
- Make sure the object is visible when the test runs
Problem: Test is waiting too long for something to happen Solution:
- Increase timeout values in your test
- Check if the expected action actually happens in the game
- Add debug logs to see what's happening
Problem: Tests work sometimes but not always Solution:
- Add wait conditions before interactions
- Check if your game loads at different speeds
- Make tests more robust with proper waits
Once you're comfortable with the basics:
- Add more Views for different game screens
- Create more comprehensive tests covering edge cases
- Set up continuous integration to run tests automatically
- Explore advanced features like data-driven tests
- Integrate with reporting tools for better test visibility
- .NET 8.0 SDK or later - Download here
- AltTester Unity SDK integrated in your Unity project
- AltTester Desktop - Download here
- Visual Studio or Visual Studio Code (optional but recommended)
- Appium Server (only if testing mobile platforms)
- Chrome browser (only if testing WebGL)
- Clone or download this template project
- Navigate to the project folder in terminal/command prompt
- Restore dependencies:
dotnet restore
- Build the project:
dotnet build
The project works with default settings out of the box for local testing. For advanced scenarios, you can customize:
ALT_TESTER_SERVER_URL- AltTester server URL (default: "127.0.0.1")ALT_TESTER_SERVER_PORT- AltTester server port (default: 13000)TEST_PLATFORM- Target platform: Android, iOS, WebGL (default: "Android")RUN_TESTS_WITH_APPIUM- Enable Appium: true/false (default: "false")RUN_TESTS_WITH_SELENIUM- Enable Selenium: true/false (default: "false")
macOS/Linux:
# Run all tests
./run_tests.sh
# Run specific test class
./run_tests.sh MainMenuTests
# Run with custom output directory
./run_tests.sh MainMenuTests resultsWindows:
REM Run all tests
run_tests.bat
REM Run specific test class
run_tests.bat MainMenuTests
REM Run with custom output directory
run_tests.bat MainMenuTests resultsmacOS/Linux:
# Change AltTester port
ALT_TESTER_SERVER_PORT=13001 ./run_tests.sh
# Run WebGL tests
TEST_PLATFORM=WebGL RUN_TESTS_WITH_SELENIUM=true ./run_tests.sh
# Run mobile tests with Appium
RUN_TESTS_WITH_APPIUM=true ./run_tests.shWindows:
REM Change AltTester port
set ALT_TESTER_SERVER_PORT=13001 && run_tests.bat
REM Run WebGL tests
set TEST_PLATFORM=WebGL && set RUN_TESTS_WITH_SELENIUM=true && run_tests.bat
REM Run mobile tests with Appium
set RUN_TESTS_WITH_APPIUM=true && run_tests.bat# Run all tests with detailed output
dotnet test --logger "console;verbosity=detailed"
# Run specific test class
dotnet test --filter "MainMenuTests"
# Run tests with custom settings
dotnet test --logger "console;verbosity=detailed" --results-directory "./TestResults"Example 1: Custom Main Menu View
namespace AltTesterProject.Views;
public class MyCustomMenuView : BaseView
{
// Define locators for your specific view
private readonly (By, string) PlayButton = (By.NAME, "PlayButtonName");
private readonly (By, string) SettingsButton = (By.NAME, "SettingsButtonName");
public MyCustomMenuView(DriverContainer drivers) : base(drivers)
{
}
// Define view actions
public void ClickPlay()
{
var playButton = FindElement(PlayButton);
playButton.Click();
}
public void OpenSettings()
{
var settingsButton = FindElement(SettingsButton);
settingsButton.Click();
}
}Example 2: Custom Gameplay View
namespace AltTesterProject.Views;
public class MyCustomGamePlayView : BaseView
{
// Define locators for your specific gameplay elements
private readonly (By, string) Player = (By.NAME, "PlayerCharacter");
private readonly (By, string) HealthBar = (By.NAME, "HealthBar");
public MyCustomGamePlayView(DriverContainer drivers) : base(drivers)
{
}
// Define gameplay actions
public void MovePlayer(float x, float y)
{
var player = FindElement(Player);
// Custom movement logic here
}
public int GetPlayerHealth()
{
var healthBar = FindElement(HealthBar);
// Extract health value logic here
return 100;
}
}namespace AltTesterProject.Tests;
[TestFixture]
[AllureFeature("My Custom Feature")]
public class MyCustomTests : BaseTest
{
private MyCustomMenuView? _menuView;
private MyCustomGamePlayView? _gamePlayView;
[SetUp]
public void TestSetUp()
{
_menuView = new MyCustomMenuView(Drivers);
_gamePlayView = new MyCustomGamePlayView(Drivers);
}
[Test]
[AllureTest("Test game flow from menu to gameplay")]
public void TestGameFlow()
{
Reporter.Log("Starting from main menu");
_menuView.ClickPlay();
Reporter.Log("Verifying gameplay loaded");
Assert.That(_gamePlayView!.GetPlayerHealth(), Is.GreaterThan(0));
}
}- Open
Views/MainMenuView.csandViews/GamePlayView.cs - Replace the example locators with actual game object names, IDs, or paths from your Unity project
- Update the locator strategies (ByName, ByTag, ByComponent) to match your game's structure
Create new view classes that inherit from BaseView following the pattern in MainMenuView.cs and GamePlayView.cs
Add new test methods to the existing test classes or create new test classes following the same pattern
The project includes basic test reporting:
- JUnit XML reports are generated automatically in the output directory
- Console output shows detailed test execution with verbose logging
- Screenshots and logs are captured automatically on test failures
For advanced reporting, you can integrate Allure or other reporting tools as needed.
- Connection refused: Ensure your Unity application is running with AltTester enabled
- Object not found: Verify locators match actual game object names/paths
- Timeout errors: Increase timeout values or check if objects are actually present
- Driver startup failures: Check that required services (Appium, etc.) are running
- Use
Reporter.Log()for detailed logging during test execution - Screenshots are automatically taken on test failures and saved to the build output directory
- Unity logs are captured automatically and saved alongside screenshots
- Check Unity Console for AltTester connection logs
- The test runners show detailed output to help with debugging
- Test results are saved in JUnit XML format for analysis
- Update locators: Edit
Views/MainMenuView.csandViews/GamePlayView.csto match your game's UI elements - Customize the tests: Modify
Tests/MainMenuTests.csto test your specific game functionality - Add more views: Create additional view objects for other screens (settings, inventory, etc.)
- Extend tests: Add more test methods or create new test classes as needed
This template provides a solid foundation with two common game views that you can build upon for any Unity game testing project.
- AltTester Documentation
- NUnit Documentation
- Allure Documentation
- Appium Documentation
- Selenium Documentation
This template is provided as-is for educational and development purposes. Modify and adapt as needed for your projects.