As matrizes de teste podem ser criadas de diferentes origens ou fluxos de trabalho. Portanto, é sempre recomendável criar funções que executem diferentes ações com base na fonte ou em outro contexto importante do teste. Para ajudar com isso, o gcloud permite que você transmita informações arbitrárias ao iniciar um teste que podem ser acessadas posteriormente na sua função. Por exemplo:
gcloud beta firebase test android run \
--app=path/to/app.apk \
--client-details testType=pr,link=https://path/to/pull-request
[null,null,["Última atualização 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 });"]]