게임 루프 테스트 실행

게임 앱이 다른 UI 프레임워크를 기반으로 빌드되면 게임 테스트를 자동화하기 어려울 수 있습니다. 게임 루프 테스트를 사용하면 기본 테스트를 Test Lab과 통합하여 선택한 기기에서 쉽게 실행할 수 있습니다. 이 가이드에서는 Firebase Test Lab을 사용하여 실행할 게임 루프 테스트를 준비하는 방법을 설명합니다.

게임 루프 테스트 정보

게임 루프 테스트란 무엇인가요?

게임 루프 테스트는 실제 플레이어의 동작을 시뮬레이션하여 빠르고 확장 가능한 방식으로 게임이 사용자에게 정상적으로 작동하는지 확인합니다. 루프는 게임 앱에서 테스트를 전체 또는 부분 실행합니다. 시뮬레이터에서 로컬로 또는 기기의 Test Lab에서 게임 루프 테스트를 실행할 수 있습니다. 게임 루프 테스트를 사용하여 다음을 수행할 수 있습니다.

  • 최종 사용자가 플레이하는 것과 같은 방식으로 게임을 진행합니다. 사용자 입력을 스크립트로 작성하거나, 사용자를 자리 비움 상태로 두거나, 사용자를 AI로 대체할 수 있습니다. 예를 들어 자동차 경주 게임에서 AI를 구현한 경우 사용자 입력을 AI 운전자로 대체할 수 있습니다.
  • 최고 품질 설정으로 게임을 실행하여 어떤 기기에서 해당 설정을 지원하는지 확인합니다.
  • 여러 셰이더를 컴파일하고 실행하며 예상대로 출력되는지 확인하는 등 기술 테스트를 실행합니다.

1단계: Test Lab의 커스텀 URL 스키마 등록

  1. Xcode에서 프로젝트 대상을 선택합니다.

  2. 정보 탭을 클릭한 다음 새 URL 유형을 추가합니다.

  3. URL 스키마 필드에 firebase-game-loop를 입력합니다. 커스텀 URL 스키마를 <dict> 태그 내에서 프로젝트의 Info.plist 구성 파일에 추가하여 등록할 수도 있습니다.

    <key>CFBundleURLTypes</key>
     <array>
         <dict>
             <key>CFBundleURLName</key>
             <string></string>
             <key>CFBundleTypeRole</key>
             <string>Editor</string>
             <key>CFBundleURLSchemes</key>
             <array>
                 <string>firebase-game-loop</string>
             </array>
         </dict>
     </array>
    

이제 앱이 Test Lab을 사용하여 테스트를 실행하도록 구성되었습니다.

2단계(선택사항): 앱 구성

여러 루프 실행

테스트에서 여러 루프(일명 시나리오)를 실행하려는 경우 시작 시 앱에서 실행할 루프를 지정해야 합니다.

앱 대리자에서 application(_:open:options:) 메서드를 재정의합니다.

Swift

func application(_app: UIApplication,
                 open url: URL
                 options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    let components = URLComponents(url: url, resolvingAgainstBaseURL: true)!
    if components.scheme == "firebase-game-loop" {
        // ...Enter Game Loop Test logic to override application(_:open:options:).
    }
    return true
}

Objective-C

- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary &lt;UIApplicationOpenURLOptionsKey, id&gt; *)options {
  if ([url.scheme isEqualToString:(@"firebase-game-loop")]) {
      // ...Enter Game Loop Test logic to override application(_:open:options:).
  }
}

테스트에서 여러 루프를 실행하면 현재 루프가 앱을 시작하는 데 사용되는 URL에 매개변수로 전달됩니다. 커스텀 URL 스키마를 가져오는 데 사용되는 URLComponents 객체를 파싱하여 현재 루프 번호를 가져올 수도 있습니다.

Swift

if components.scheme == "firebase-game-loop" {
    // Iterate over all parameters and find the one with the key "scenario".
    let scenarioNum = Int(components.queryItems!.first(where: { $0.name == "scenario" })!.value!)!
    // ...Write logic specific to the current loop (scenarioNum).
}

Objective-C

if ([url.scheme isEqualToString:(@"firebase-game-loop")]) {
    // Launch the app as part of a game loop.
    NSURLComponents *components = [NSURLComponents componentsWithURL:url
                                             resolvingAgainstBaseURL:YES];
    for (NSURLQueryItem *item in [components queryItems]) {
        if ([item.name isEqualToString:@"scenario"]) {
            NSInteger scenarioNum = [item.value integerValue];
            // ...Write logic specific to the current loop (scenarioNum).
        }
    }
}

조기에 테스트 종료

기본적으로 게임 루프 테스트는 모든 루프가 실행되더라도 제한 시간인 5분이 될 때까지 계속 실행됩니다. 제한 시간에 도달하면 테스트가 종료되고 대기 중인 루프가 취소됩니다. 앱의 AppDelegate에서 Test Lab의 커스텀 URL 스키마 firebase-game-loop-complete를 호출하여 테스트 속도를 높이거나 조기에 종료할 수 있습니다. 예를 들면 다음과 같습니다.

Swift

/// End the loop by calling our custom url scheme.
func finishLoop() {
    let url = URL(string: "firebase-game-loop-complete://")!
    UIApplication.shared.open(url)
}

Objective-C

- (void)finishLoop {
  UIApplication *app = [UIApplication sharedApplication];
  [app openURL:[NSURL URLWithString:@"firebase-game-loop-complete://"]
      options:@{}
completionHandler:^(BOOL success) {}];
}

게임 루프 테스트는 현재 루프를 종료하고 다음 루프를 실행합니다. 실행할 루프가 더 이상 없으면 테스트가 종료됩니다.

커스텀 테스트 결과 작성

게임 루프 테스트를 구성하여 커스텀 테스트 결과를 기기의 파일 시스템에 작성할 수 있습니다. 이렇게 하면 테스트 실행이 시작되면 Test Lab에서 결과 파일을 테스트 기기의 GameLoopsResults 디렉터리에 저장합니다(직접 만들어야 함). 테스트가 끝나면 Test Lab에서 모든 파일을 GameLoopResults 디렉터리에서 프로젝트 버킷으로 이동합니다. 테스트를 설정할 때 다음 사항에 유의하세요.

  • 모든 결과 파일은 파일 형식, 크기 또는 수량에 관계없이 업로드됩니다.

  • Test Lab은 테스트의 모든 루프가 완료될 때까지 테스트 결과를 처리하지 않으므로 테스트에 출력을 쓰는 여러 루프가 포함된 경우 루프를 고유한 결과 파일에 추가하거나 루프마다 결과 파일을 만들어야 합니다. 이렇게 하면 이전 루프의 결과를 덮어쓰지 않게 됩니다.

커스텀 테스트 결과를 작성하도록 테스트를 설정하려면 다음 안내를 따르세요.

  1. 앱의 Documents 디렉터리에 GameLoopResults라는 디렉터리를 만듭니다.

  2. 앱 코드의 모든 위치(예: 앱 대리자)에서 다음을 추가합니다.

    Swift

    /// Write to a results file.
    func writeResults() {
      let text = "Greetings from game loops!"
      let fileName = "results.txt"
      let fileManager = FileManager.default
      do {
    
      let docs = try fileManager.url(for: .documentDirectory,
                                     in: .userDomainMask,
                                     appropriateFor: nil,
                                     create: true)
      let resultsDir = docs.appendingPathComponent("GameLoopResults")
      try fileManager.createDirectory(
          at: resultsDir,
          withIntermediateDirectories: true,
          attributes: nil)
      let fileURL = resultsDir.appendingPathComponent(fileName)
      try text.write(to: fileURL, atomically: false, encoding: .utf8)
      } catch {
        // ...Handle error writing to file.
      }
    }
    

    Objective-C

    /// Write to a results file.
    - (void)writeResults:(NSString *)message {
        // Locate and create the results directory (if it doesn't exist already).
        NSFileManager *manager = [NSFileManager defaultManager];
        NSURL* url = [[manager URLsForDirectory:NSDocumentDirectory
                                      inDomains:NSUserDomainMask] lastObject];
        NSURL* resultsDir = [url URLByAppendingPathComponent:@"GameLoopResults"
                                                 isDirectory:YES];
        [manager createDirectoryAtURL:resultsDir
          withIntermediateDirectories:NO
                           attributes:nil
                                error:nil];
    
        // Write the result message to a text file.
        NSURL* resultFile = [resultsDir URLByAppendingPathComponent:@"result.txt"];
        if ([manager fileExistsAtPath:[resultFile path]]) {
            // Append to the existing file
            NSFileHandle *handle = [NSFileHandle fileHandleForWritingToURL:resultFile
                                                                     error:nil];
            [handle seekToEndOfFile];
            [handle writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
            [handle closeFile];
        } else {
            // Create and write to the file.
            [message writeToURL:resultFile
                     atomically:NO
                       encoding:NSUTF8StringEncoding error:nil];
        }
    }
    

3단계: 앱에 서명

  1. 앱의 모든 아티팩트가 서명되었는지 확인합니다. 예를 들어 프로비저닝 프로필 및 ID와 같은 서명 설정을 지정하여 Xcode를 통해 이 작업을 수행할 수 있습니다. 자세한 내용은 Apple 코드 서명을 참고하세요.

4단계: 업로드할 앱 패키징

앱의 IPA 파일을 생성합니다(나중에 이 파일을 찾아야 함).

  1. 표시되는 드롭다운 메뉴에서 제품 > 보관처리를 클릭합니다. 가장 최근의 보관 파일을 선택한 다음 앱 배포를 클릭합니다.

  2. 표시되는 창에서 개발 > 다음을 클릭합니다.

  3. 선택사항: 더 빨리 빌드하려면 비트코드에서 다시 빌드 옵션을 선택 해제하고 다음을 클릭합니다. Test Lab을 사용하면 테스트를 실행하기 위해 앱을 축소하거나 다시 빌드할 필요가 없으므로 이 옵션을 사용 중지해도 아무 문제가 없습니다.

  4. 내보내기를 클릭한 다음 앱의 IPA 파일을 다운로드할 디렉터리를 입력합니다.

5단계: 앱 서명 확인

  1. .ipa 파일의 압축을 푼 다음 codesign --verify --deep --verbose /path/to/MyApp.app을 실행하여 앱 서명을 확인합니다. 여기서 'MyApp'은 압축을 푼 폴더 안에 있는 앱 이름입니다(프로젝트에 따라 다름). 예상 출력은 MyApp.app: valid on disk입니다.

6단계: 로컬에서 테스트 실행

Test Lab으로 테스트를 실행하기 전에 로컬에서 테스트를 실행하여 동작을 확인할 수 있습니다. 로컬에서 테스트하려면 시뮬레이터에서 게임 앱을 로드하고 다음을 실행합니다.

xcrun simctl openurl SIMULATOR_UDID firebase-game-loop://
  • instruments -s devices 명령어를 실행하여 시뮬레이터의 UDID를 찾을 수 있습니다.

  • 시뮬레이터가 하나만 실행되는 경우 SIMULATOR_UDID 대신 특수 문자열 "booted"를 입력합니다.

테스트에 여러 루프가 포함된 경우 루프 번호를 scenario 플래그에 전달하여 실행할 루프를 지정할 수 있습니다. 로컬에서 테스트를 실행할 때 한 번에 하나의 루프만 실행할 수 있습니다. 예를 들어 루프 1, 2, 5를 실행하려면 루프마다 별도의 명령어를 실행해야 합니다.

xcrun simctl openurl SIMULATOR_UDID firebase-game-loop://?scenario=1
xcrun simctl openurl SIMULATOR_UDID firebase-game-loop://?scenario=2
xcrun simctl openurl SIMULATOR_UDID firebase-game-loop://?scenario=5

다음 단계

Firebase Console 또는 gcloud CLI를 사용하여 테스트를 실행합니다.