ทริกเกอร์ฟังก์ชันเมื่อทดสอบเสร็จสมบูรณ์ของ 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 ...
});