이 가이드에서는 Firebase Test Lab에서 테스트할 XCTest를 준비하는 방법을 설명합니다.
1단계: 프로젝트의 파생 데이터 위치 구성
Xcode는 컴파일된 iOS 아티팩트(빌드한 모든 테스트 포함)를 파생 데이터 디렉터리에 저장합니다. 원하는 경우 이 디렉터리의 기본 위치를 유지할 수 있지만 특히 Test Lab을 사용하여 테스트를 자주 실행하려는 경우 파일에 보다 쉽게 액세스할 수 있는 위치를 선택하는 것이 도움이 됩니다.
Xcode에서 프로젝트를 엽니다.
macOS 메뉴 바에서 파일 > 프로젝트 설정...을 선택합니다.
파생 데이터 드롭다운을 기본 위치에서 커스텀 위치로 변경합니다.
드롭다운 아래의 필드에서 테스트를 출력할 Xcode의 위치를 선택합니다. (FOLDER_WITH_TEST_OUTPUT)
2단계: 일반 테스트 파일 빌드
Test Lab은 XCTest 프레임워크를 사용하여 단위 테스트 및 UI 테스트를 실행합니다.
Test Lab 기기에서 앱의 XCTest를 실행하려면 일반 iOS 기기에서 테스트할 수 있도록 앱을 빌드합니다.
앱과 테스트의 모든 아티팩트가 서명되었는지 확인합니다. 예를 들어 프로비저닝 프로필 및 ID와 같은 서명 설정을 지정하여 Xcode를 통해 이 작업을 수행할 수 있습니다. 자세한 내용은 Apple 코드 서명을 참고하세요.
codesign --verify --deep --verbose /path/to/MyApp.app을 실행하여 앱 서명을 확인합니다. 여기서 'MyApp'은 압축을 푼 폴더 안에 있는 앱 이름입니다. 이는 프로젝트마다 다릅니다.
예상 출력은 MyApp.app: valid on disk입니다.
XCUITest를 실행 중이라면 codesign --verify --deep --verbose /path/to/MyTest-Runner.app을 실행하여 테스트 및 실행자를 확인해야 합니다. 여기서 'MyTest'는 압축을 푼 폴더 안에 있는 실행자 이름입니다. 이는 프로젝트마다 다릅니다. 예상 출력은 MyTest-Runner.app: valid on disk입니다.
4단계: 앱 패키징 및 업로드 테스트
테스트가 성공적으로 빌드되면 압축하여 Test Lab에 업로드합니다.
cd FOLDER_WITH_TEST_OUTPUT/Build/Products : \
zip -r MyTests.zip Debug-iphoneos YOUR_SCHEME_iphoneosDEPLOYMENT_TARGET-arm64.xctestrun
테스트 파일을 수동으로 압축하여 테스트를 패키징할 수도 있습니다.
Finder를 열고 FOLDER_WITH_TEST_OUTPUT으로 이동합니다.
프로젝트 이름이 프리픽스로 되어있는 폴더를 열고 내부의 Build/Products 폴더로 이동합니다.
Debug-iphoneos 및 YOUR_SCHEME_iphoneosDEPLOYMENT_TARGET-arm64.xctestrun 폴더를 선택한 후 압축합니다.
5단계: (선택사항) 로컬에서 테스트 실행
Test Lab으로 테스트를 실행하기 전에 다음과 같이 USB 연결 기기로 로컬에서 테스트를 실행하여 동작의 품질을 검사할 수 있습니다.
[null,null,["최종 업데이트: 2025-08-16(UTC)"],[],[],null,["# Run an XCTest\n\n\u003cbr /\u003e\n\nThis guide describes how to prepare an XCTest for testing in\nFirebase Test Lab.\n\n**Step 1**: Configure your project's Derived Data location\n----------------------------------------------------------\n\nXcode places compiled iOS artifacts, including any tests you build, in a Derived\nData directory. It is possible to keep the default location for that directory,\nif you'd like, but it's often helpful to choose a more easily-accessible place\nfor the files, especially if you're going to be running tests with Test Lab\noften:\n\n1. Open your project in Xcode.\n2. In the macOS menu bar, select **File** \\\u003e **Project Settings...**\n3. Change the **Derived Data** drop-down from **Default Location** to **Custom Location**.\n4. In the field below the drop-down, select a location for Xcode to output your tests to. (This is your \u003cvar class=\"edit\" scope=\"FOLDER_WITH_TEST_OUTPUT\" translate=\"no\"\u003eFOLDER_WITH_TEST_OUTPUT\u003c/var\u003e)\n\n**Step 2**: Build a generic test file\n-------------------------------------\n\nTest Lab runs unit tests and UI tests using the\n[XCTest](https://developer.apple.com/documentation/xctest) framework.\nTo run your app's XCTests on Test Lab devices, build it for testing on a\nGeneric iOS Device:\n\n1. From the device drop-down at the top of your Xcode workspace window, select **Generic iOS Device**.\n2. In the macOS menu bar, select **Product** \\\u003e **Build For** \\\u003e **Testing**.\n\nAs an alternative, you can build your XCTest from the command line.\nUse the following command in a terminal: \n\n#### project\n\n```\nxcodebuild -project PATH/TO/YOUR_WORKSPACE/YOUR_PROJECT.xcodeproj \\\n -scheme YOUR_SCHEME \\\n -derivedDataPath FOLDER_WITH_TEST_OUTPUT \\\n -sdk iphoneos build-for-testing\n```\n\n#### workspace\n\n```\nxcodebuild -workspace PATH/TO/YOUR_WORKSPACE.xcworkspace \\\n -scheme YOUR_SCHEME \\\n -derivedDataPath FOLDER_WITH_TEST_OUTPUT \\\n -sdk iphoneos build-for-testing\n```\n\n**Step 3**: Sign your test and verify\n-------------------------------------\n\n1. Make sure all artifacts in the app and test are signed. For example, you can\n do this through Xcode by specifying signing settings like provisioning profile\n and identity. For more information, see\n [Apple Code Signing](https://developer.apple.com/support/code-signing/).\n\n | **Note** : Test Lab re-signs your app with its own provisioning profile and certificate.\n2. Verify app signature by running\n `codesign --verify --deep --verbose /path/to/MyApp.app` where \"MyApp\" is the\n name of the app inside the unzipped folder. This varies for each project.\n Expected output is `MyApp.app: valid on disk`.\n\n3. If you are running an XCUITest, then you need to verify the test and runner\n by running `codesign --verify --deep --verbose /path/to/MyTest-Runner.app` where\n \"MyTest\" is the name of the runner inside the unzipped folder. This varies for\n each project. Expected output is `MyTest-Runner.app: valid on disk`.\n\n**Step 4**: Package your app and test for uploading\n---------------------------------------------------\n\n1. After your test successfully builds, zip it for upload to Test Lab:\n\n ```\n cd FOLDER_WITH_TEST_OUTPUT/Build/Products : \\\n zip -r MyTests.zip Debug-iphoneos YOUR_SCHEME_iphoneosDEPLOYMENT_TARGET-arm64.xctestrun\n ```\n\nYou can also package up your test by compressing the test files manually:\n\n1. Open Finder and navigate to\n \u003cvar class=\"edit\" scope=\"FOLDER_WITH_TEST_OUTPUT\" translate=\"no\"\u003eFOLDER_WITH_TEST_OUTPUT\u003c/var\u003e.\n\n2. Open the folder that has your project name as a prefix, then navigate to\n `Build/Products` folder inside.\n\n3. Select the folders `Debug-iphoneos` and\n \u003cvar class=\"edit\" scope=\"YOUR_SCHEME\" translate=\"no\"\u003eYOUR_SCHEME\u003c/var\u003e`_iphoneos`\u003cvar class=\"edit\" scope=\"DEPLOYMENT_TARGET\" translate=\"no\"\u003eDEPLOYMENT_TARGET\u003c/var\u003e`-arm64.xctestrun`\n and then compress them.\n\n**Step 5**: (Optional) Run your test locally\n--------------------------------------------\n\nBefore running your test with Test Lab, you can run it locally with\na USB-connected device to quality check its behavior: \n\n```\nxcodebuild test-without-building \\\n -xctestrun \"Derived Data/Build/Products/YOUR_SCHEME.xctestrun\" \\\n -destination id=your-phone-id\n```\n\nNext steps\n----------\n\nUpload and run your test in the [Firebase console](/docs/test-lab/ios/firebase-console)\nor the [gcloud CLI](/docs/test-lab/ios/command-line)."]]