테스트 매트릭스는 다양한 소스 또는 워크플로에서 생성될 수 있습니다. 따라서 대부분의 경우 테스트의 소스 또는 기타 중요 컨텍스트를 기반으로 다양한 작업을 수행하는 함수를 생성하는 것이 바람직합니다. 이를 위해 gcloud를 사용하면 테스트 시작 시 임의의 정보를 전달할 수 있으며 이후 함수에서 이 정보에 액세스할 수 있습니다. 예를 들면 다음과 같습니다.
gcloud beta firebase test android run \
--app=path/to/app.apk \
--client-details testType=pr,link=https://path/to/pull-request
[null,null,["최종 업데이트: 2025-08-16(UTC)"],[],[],null,["\u003cbr /\u003e\n\n2nd gen 1st gen \n\nTrigger a function on TestMatrix completion\n\nCreate a new function that triggers when a TestMatrix completes with the event handler\n`functions.testLab.testMatrix().onComplete()`: \n\n exports.sendEmailNotification = functions.testLab.testMatrix().onComplete((testMatrix) =\u003e {\n // ...\n });\n\nHandle test states and outcomes\n\nEach execution of your function is passed a [`TestMatrix`](/docs/reference/functions/firebase-functions.testlab.testmatrix)\nwhich includes the final state of the matrix and details to help understand problems. \n\n exports.handleTestMatrixCompletion = functions.testLab.testMatrix().onComplete(testMatrix =\u003e {\n const matrixId = testMatrix.testMatrixId;\n switch (testMatrix.state) {\n case 'FINISHED':\n console.log(`TestMatrix ${matrixId} finished with outcome: ${testMatrix.outcomeSummary}`);\n break;\n case 'INVALID':\n console.log(`TestMatrix ${matrixId} was marked as invalid: ${testMatrix.invalidMatrixDetails}`);\n break;\n default:\n console.log(`TestMatrix ${matrixId} completed with state ${testMatrix.state}`);\n }\n return null;\n });\n\nAccess client details\n\nTest matrices may be created from different sources or workflows. It is therefore often desirable to\ncreate functions that perform different actions based on the source or other important context of\nthe test. To help with this, `gcloud` allows you to pass arbitrary information when starting a test\nthat can be accessed later in your function. For example: \n\n gcloud beta firebase test android run \\\n --app=path/to/app.apk \\\n --client-details testType=pr,link=https://path/to/pull-request\n\nExample function: \n\n exports.notifyOnPullRequestFailure = functions.testLab.testMatrix().onComplete(testMatrix =\u003e {\n if (testMatrix.clientInfo.details['testType'] != 'pr') {\n // Not a pull request\n return null;\n }\n\n if (testMatrix.state == 'FINISHED' && testMatrix.outcomeSummary == 'SUCCESS') {\n // No failure\n return null;\n }\n\n const link = testMatrix.clientInfo.details['link'];\n let message = `Test Lab validation for pull request ${link} failed. `;\n\n if (!!testMatrix.resultStorage.resultsUrl) {\n message += `Test results available at ${testMatrix.resultStorage.resultsUrl}. `;\n }\n\n // Send notification here ...\n });"]]