Chaque exécution de votre fonction reçoit un TestMatrix qui inclut l'état final de la matrice et des détails pour vous aider à comprendre les problèmes.
Les matrices de test peuvent être créées à partir de différentes sources ou de différents workflows. Il est donc souvent souhaitable de créer des fonctions qui effectuent différentes actions en fonction de la source ou d'un autre contexte important du test. Pour vous aider, gcloud vous permet de transmettre des informations arbitraires lorsque vous démarrez un test, qui seront accessibles ultérieurement dans votre fonction. Exemple :
gcloud beta firebase test android run \
--app=path/to/app.apk \
--client-details testType=pr,link=https://path/to/pull-request
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/16 (UTC).
[null,null,["Dernière mise à jour le 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 });"]]