If you’re looking for a way to run automated tests on a unity game without using Appium, this article could help you. We present the necessary steps to run some Java tests on iOS. To get started, clone this example project from Gitlab, then follow the steps described below or check out the tutorial video.
Setup for testing
The first step to writing automated tests in Java using AltUnity Tester is to install the altunitytester Maven dependency for the AltUnity driver:
<dependency> <groupId>ro.altom</groupId> <artifactId>altunitytester</artifactId> <version>1.5.3</version> </dependency>
The Java tests are run using the mvn test command, which is present in the script which launches the build(see the last section in this article).
After the installation is complete, the tests can be run either by connecting the target device directly to the computer using the USB cable, or by running them through the network.
If the tests are run by direct USB connection, the target IP is set to localhost (127.0.0.1) and port forwarding needs to be done. The port to be forwarded is the one on which the game will run (by default it’s 13000).If the tests are run by the wireless connection, you need to make sure the computer and the target device are in the same network, and the target IP is updated to the one corresponding to the target device. To update the port, use the config.properties file from the src/main/resources directory.
XCode build: main challenges
To start and run the tests using the command line or a bash script, the xcodebuild command is used. For the build to succeed, the project has to be configured from the XCode. During the configuration process, a few challenges were encountered:
- Development certificate: by automatically signing the app, the “Apple Development” certificate is set. However, for the app to run properly, the “iOS Developer” certificate must be set;
- Provisioning profile: depending on the development team, a user-defined provisioning profile may be set, which conflicts with the automatically built one. If that is the case, the manual profile must be deleted;
- Both targets configured: the Unity-iPhone and the Unity-iPhone Tests targets must be set the signing options, otherwise the command line instructions won’t execute the build.
Running the tests from the script
The launch-iOS-game.sh script is run in order to open the app and execute the tests automatically. It can be successfully run only when the target device is directly connected through USB. On running the script, the following operations are performed:
- Set the user-specified target device
- Run a clean build of the app
- Forward the port 13000 used by the target
- Run the Java tests with mvn test
- Kill the processes before shutdown