راه‌اندازهای «آزمایشگاه آزمایشی» (نسل اول)

راه‌اندازی تابع در تکمیل TestMatrix

تابع جدیدی ایجاد کنید که وقتی TestMatrix با کنترل‌کننده رویداد تکمیل می‌شود راه‌اندازی شود functions.testLab.testMatrix().onComplete():

exports.sendEmailNotification = functions.testLab.testMatrix().onComplete((testMatrix) => {
  // ...
});

مدیریت وضعیت‌ها و پیامدهای آزمایش

هر اجرای تابع شما TestMatrix به‌همراه وضعیت نهایی ماتریس و جزئیاتی برای کمک به درک مشکلات ارسال می‌شود.

exports.handleTestMatrixCompletion = functions.testLab.testMatrix().onComplete(testMatrix => {
  const matrixId = testMatrix.testMatrixId;
  switch (testMatrix.state) {
    case 'FINISHED':
      console.log(`TestMatrix ${matrixId} finished with outcome: ${testMatrix.outcomeSummary}`);
      break;
    case 'INVALID':
      console.log(`TestMatrix ${matrixId} was marked as invalid: ${testMatrix.invalidMatrixDetails}`);
      break;
    default:
      console.log(`TestMatrix ${matrixId} completed with state ${testMatrix.state}`);
  }
  return null;
});

دسترسی به جزئیات کارخواه

ماتریس‌های آزمایش ممکن است از منابع یا گردش‌های کار مختلف ایجاد شوند. بنابراین اغلب مطلوب است که توابعی ایجاد کنید که براساس منبع یا زمینه مهم دیگر آزمایش، کنش‌های مختلفی را انجام دهند. برای کمک به این کار، gcloud به شما امکان می‌دهد هنگام شروع آزمایش، اطلاعات دلخواهی را ارسال کنید که بعداً در تابع شما قابل‌دسترسی است. برای مثال:

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

تابع نمونه:

exports.notifyOnPullRequestFailure = functions.testLab.testMatrix().onComplete(testMatrix => {
  if (testMatrix.clientInfo.details['testType'] != 'pr') {
    // Not a pull request
    return null;
  }

  if (testMatrix.state == 'FINISHED' && testMatrix.outcomeSummary == 'SUCCESS') {
    // No failure
    return null;
  }

  const link = testMatrix.clientInfo.details['link'];
  let message = `Test Lab validation for pull request ${link} failed. `;

  if (!!testMatrix.resultStorage.resultsUrl) {
    message += `Test results available at ${testMatrix.resultStorage.resultsUrl}. `;
  }

  // Send notification here ...
});