Skip to content

Create test build and run XCTest

Yuxing Hu edited this page Mar 22, 2023 · 5 revisions

This guide describes preparing an XCTest for testing in Hydra Lab.

Step 1: Configure your project's Derived Data location

Xcode places compiled iOS artifacts in a Derived Data directory, including any tests you build. It is possible to keep the default location for that directory if you'd like, but it's often helpful to choose a more easily-accessible place for the files, especially if you're going to be running tests with Hydra Lab often:

  1. Open your project in Xcode.
  2. In the macOS menu bar, select File > Workspace Settings(or Project Settings)...
  3. Change the Derived Data dropdown from Default Location to Custom Location.
  4. In the field below the dropdown, select a location for Xcode to output your tests to.
image

Step 2: Build a generic test file

Hydra Lab runs unit tests and UI tests using the XCTest framework. To run your app's XCTests on Hydra Lab devices, build it for testing on a Generic iOS Device:

  1. From the device dropdown at the top of your Xcode workspace window, select Generic iOS Device.
  2. In the macOS menu bar, select Product > Build For > Testing.
image

Step 3: Package your app for uploading

Finally, build and package your test for upload to Hydra Lab by compressing the test files you built into a .zip file.

  1. To build your XCTest, use the following command in a terminal (take workspace as an example):
xcodebuild -workspace PATH/TO/YOUR_WORKSPACE.xcworkspace \
-scheme YOUR_SCHEME \
-derivedDataPath FOLDER_WITH_TEST_OUTPUT \
-sdk iphoneos build-for-testing
  1. After your test successfully builds, zip it for upload to Hydra Lab:
cd FOLDER_WITH_TEST_OUTPUT/Build/Products : \
zip -r MyTests.zip Debug-iphoneos YOUR_SCHEME_iphoneosDEPLOYMENT_TARGET-arm64.xctestrun

You can also package up your test by compressing the test files manually, be sure to select the folders Debug-iphoneos and PROJECT_NAME_iphoneosDEVELOPMENT_TARGET-arm64.xctestrun and then compress them.

image

Step 4. (Optional) Run your test locally

Before running your test with Hydra Lab, you can run it locally with a USB-connected device to quality check its behavior:

xcodebuild test-without-building \
    -xctestrun "Derived Data/Build/Products/YourApp.xctestrun" \
    -destination id=your-phone-id

Step 5. Upload your zip file to Hydra Lab

After you successfully extract the zip file, it's time to submit it to Hydra Lab.

  1. Select Runner from the left panel
  2. Click the upload button to submit the zip file

You should see your package (this may take some time if your zip is relatively large) displayed on the table.

Step 6. Trigger the XCTest

  1. Select Runner from the left panel
  2. Find the zip package you just uploaded in the table
  3. Click the run button, choose XCTest as the test type
  4. Choose the target machine (we only support real devices for now), and run the test

The result will be displayed in the task panel.

Also see

Clone this wiki locally