Firebase is back at Google I/O on May 10! Register now

Firebase 測試實驗室觸發器

透過集合功能整理內容 你可以依據偏好儲存及分類內容。

您可以觸發函數以響應 Firebase 測試實驗室中測試矩陣的完成。例如,如果測試失敗,您可以通知 Slack 頻道或發送電子郵件。

在 TestMatrix 完成時觸發一個函數

要觸發 Firebase 測試實驗室功能,請使用firebase-functions/v2/testLab子包。您可以在 TestMatrix 使用onTestMatrixCompleted()事件處理程序完成時觸發函數。

在此示例中,函數從 CloudEvent 對象檢索TestMatrix數據並將相應的測試結果發送到 Slack 通道:

exports.posttestresultstoslack = onTestMatrixCompleted(
    {secrets: ["SLACK_WEBHOOK_URL"]},
    async (event) => {
    // Obtain Test Matrix properties from the CloudEvent
      const {testMatrixId, state, outcomeSummary} = event.data;

      // Create the title of the message
      const title = `${getSlackmoji(state)} ${getSlackmoji(
          outcomeSummary,
      )} ${testMatrixId}`;

      // Create the details of the message
      const details = `Status: *${state}* ${getSlackmoji(
          state,
      )}\nOutcome: *${outcomeSummary}* ${getSlackmoji(outcomeSummary)}
    `;

      // Post the message to slack
      const slackResponse = await postToSlack(title, details);

      // Log the response
      logger.log(slackResponse);
    });

訪問客戶詳細信息

可以從不同的來源或工作流程創建測試矩陣。因此,通常需要創建根據源或測試的其他重要上下文執行不同操作的函數。為了解決這個問題, gcloud允許您在開始測試時傳遞任意信息,這些信息稍後可以在您的函數中訪問。例如:

gcloud beta firebase test android run \
    --app=path/to/app.apk \
    --client-details testType=pr,link=<path/to/pull-request>