Kiểm thử tiện ích bổ sung dành cho Trình chỉnh sửa
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Bạn nên kiểm thử kỹ lưỡng các tiện ích bổ sung trước khi phát hành để đảm bảo rằng các tiện ích đó hoạt động như dự kiến. Apps Script cho phép bạn kiểm thử tiện ích bổ sung cho Trình chỉnh sửa đang phát triển trên các tệp Trang tính, Biểu mẫu hoặc Trang trình bày cụ thể của Google Tài liệu. Bạn có thể sử dụng tính năng này để:
Xác minh rằng tiện ích bổ sung được viết trong tập lệnh độc lập hoạt động như dự kiến khi được áp dụng cho một trang tính, tài liệu, bản trình bày hoặc biểu mẫu.
Xác minh rằng tiện ích bổ sung hoạt động như dự kiến khi thực hiện trên một tài liệu và nội dung cụ thể.
Kiểm thử và so sánh phiên bản hiện tại với phiên bản trước của tiện ích bổ sung.
Tạo một bản triển khai kiểm thử
Việc triển khai kiểm thử là sự kết hợp giữa một tiện ích bổ sung và một tài liệu kiểm thử.
Sau khi bạn phát triển một phiên bản tập lệnh và muốn kiểm thử phiên bản đó dưới dạng tiện ích bổ sung, hãy làm theo các bước sau:
Nếu bạn chưa có, hãy tạo một bảng tính, tài liệu, bản trình bày hoặc biểu mẫu để kiểm thử tiện ích bổ sung.
Mở dự án tập lệnh chứa tiện ích bổ sung của bạn.
Nhấp vào Triển khai>Kiểm thử bản triển khai.
Bên cạnh Chọn loại, hãy nhấp vào Bật loại triển khai settings rồi chọn Tiện ích bổ sung cho Trình chỉnh sửa.
Nhấp vào Tạo thử nghiệm mới hoặc Thêm thử nghiệm.
Chọn một phiên bản mã hoặc chọn Mã mới nhất.
Trong phần Config (Cấu hình), hãy chọn trạng thái uỷ quyền ban đầu cho kiểm thử.
Trong mục Tài liệu kiểm thử, hãy nhấp vào Chưa chọn tài liệu nào. Chọn tệp Trang tính, Tài liệu, Trang trình bày hoặc Biểu mẫu mà bạn muốn dùng để kiểm thử tiện ích bổ sung rồi nhấp vào Chèn.
Nhấp vào Lưu bài kiểm thử.
Tất cả các bản triển khai kiểm thử đã lưu sẽ xuất hiện trong hộp thoại Test deployments (Triển khai kiểm thử). Điều này cho phép bạn xem lại cùng một lượt triển khai kiểm thử sau này.
Chạy một bản triển khai thử nghiệm
Nếu có một hoặc nhiều lượt triển khai kiểm thử đã lưu, bạn có thể chạy một trong số đó bằng cách làm theo các bước sau:
Mở dự án tập lệnh chứa tiện ích bổ sung.
Nhấp vào Triển khai>Kiểm thử bản triển khai.
Trong mục Saved Tests (Kiểm thử đã lưu), hãy chọn nút chọn bên cạnh bản triển khai kiểm thử đã lưu mà bạn muốn chạy rồi nhấp vào Execute (Thực thi).
Tài liệu kiểm thử sẽ mở trong một thẻ mới. Tiện ích bổ sung đang ở trạng thái uỷ quyền được chỉ định trong quá trình triển khai kiểm thử. Bạn có thể xác minh rằng các chức năng bổ sung hoạt động như dự kiến bằng cách tương tác với trình đơn và các thành phần trên giao diện người dùng.
Thông tin chi tiết về kiểm thử
Có một số điều cần lưu ý khi kiểm thử tiện ích bổ sung của Trình chỉnh sửa theo cách này:
Trình kích hoạt có thể cài đặt không được hỗ trợ khi kiểm thử. Không thể kiểm thử chức năng phụ thuộc vào trình kích hoạt có thể cài đặt.
Trong khi chạy một quá trình triển khai kiểm thử được đặt để kiểm thử bằng mã mới nhất, bạn có thể thấy các thay đổi được lưu vào tập lệnh tiện ích bổ sung bằng cách làm mới tài liệu kiểm thử.
Tài liệu kiểm thử có một URL mà bạn có thể chia sẻ với người chỉnh sửa tài liệu kiểm thử gốc. Bằng cách này, bạn có thể dễ dàng cộng tác với những người khác trong khi kiểm thử và phát triển.
Nếu tiện ích bổ sung của bạn sử dụng Dịch vụ thuộc tính, thì các thuộc tính sẽ vẫn tồn tại và có sẵn trong lần chạy tiếp theo của quá trình triển khai kiểm thử.
Ngoài ra, mọi hoạt động triển khai kiểm thử sử dụng cùng một tổ hợp tiện ích bổ sung và tài liệu kiểm thử đều có quyền truy cập vào cùng một thông tin tài sản. Ví dụ: nếu bạn tạo hai lần triển khai kiểm thử, thì các thuộc tính được lưu trong khi chạy lần triển khai đầu tiên sẽ có sẵn trong khi chạy lần triển khai thứ hai và ngược lại, nhưng chỉ khi các lần triển khai sử dụng cùng một tập lệnh và tài liệu kiểm thử.
Nếu chạy một quá trình triển khai kiểm thử, bạn có thể được nhắc cấp quyền nếu chưa chạy tập lệnh trước đó. Xin lưu ý rằng việc uỷ quyền cho một tập lệnh trong khi kiểm thử cũng sẽ uỷ quyền cho tập lệnh đó bên ngoài quá trình kiểm thử.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2024-12-22 UTC."],[[["\u003cp\u003eApps Script allows developers to test editor add-ons directly within Google Docs, Sheets, Slides, or Forms to verify functionality and installation flow.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can create test deployments to specify add-on versions, authorization states, and associated documents for controlled testing environments.\u003c/p\u003e\n"],["\u003cp\u003eSaved test deployments can be executed repeatedly, enabling developers to iterate on their add-ons and observe changes in real-time within the test document.\u003c/p\u003e\n"],["\u003cp\u003eWhile offering valuable testing capabilities, test deployments have limitations such as not supporting installable triggers and shared property persistence across deployments using the same add-on and document.\u003c/p\u003e\n"],["\u003cp\u003eTest deployments provide a shareable URL for collaborative testing and may require authorization for the script, both within and outside the testing environment.\u003c/p\u003e\n"]]],["To test add-ons in development, create a test deployment linking a script version to a specific Google Docs, Sheets, Forms, or Slides file. Select the add-on's authorization state and save the test. Run saved tests by selecting them in the \"Test deployments\" dialog and clicking \"Execute.\" During testing, changes to the script can be viewed by refreshing the test document; the test document URL is shareable for collaboration. Any properties created are also persisted across multiple test deployments.\n"],null,["# Test an Editor add-on\n\nAdd-ons should be tested thoroughly prior to publishing to ensure they\nbehave as intended. Apps Script lets you test\n[Editor add-ons](/workspace/add-ons/concepts/types#editor_add-ons)\nin development on specific Google Docs Sheets, Forms, or Slides files. This\ncan be used to:\n\n- Verify that an add-on written in a standalone script functions as intended when applied to a sheet, doc, presentation, or form.\n- Verify that the add-on installation flow works as intended, particularly for different initial [authorization lifecycle states](/workspace/add-ons/concepts/editor-auth-lifecycle#the_complete_lifecycle) ([installed, enabled, or both](/workspace/add-ons/concepts/editor-auth-lifecycle#installed_versus_enabled)).\n- Verify that the add-on functions as intended when acting on a particular document and its contents.\n- Test and compare the current and previous versions of the add-on.\n\nCreate a test deployment\n------------------------\n\nA test deployment is the combination of an add-on and a test document.\nOnce you have a script version developed and would like to test it as an add-on,\nfollow these steps:\n\n1. If you don't have one already, create a spreadsheet, document, presentation, or form to test the add-on with.\n2. Open the script project containing your add-on.\n3. Click **Deploy** \\\u003e **Test deployments**.\n4. Next to **Select type** , click Enable deployment types settings and select **Editor add-on**.\n5. Click **Create new test** or **Add test**.\n6. Choose a code version or select **Latest Code**.\n7. In the **Config** section, select the initial [authorization state](/workspace/add-ons/concepts/editor-auth-lifecycle#installed_versus_enabled) for the test.\n8. Under **Test document** , click **No document selected** . Select the Sheets, Docs, Slides, or Forms file you want to use to test the add-on and click **Insert**.\n9. Click **Save test**.\n\nAll saved test deployments appear in the **Test deployments** dialog. This lets\nyou revisit the same test deployment later on.\n\nRun a test deployment\n---------------------\n\nIf you have one or more saved test deployments, you can run one of them by\nfollowing these steps:\n\n1. Open the script project containing your add-on.\n2. Click **Deploy** \\\u003e **Test deployments**.\n3. Under **Saved Tests** , select the radio button next to the saved test deployment you want to run and click **Execute**.\n\nThe test document opens in a new tab. The add-on is in the\n[authorization state](/workspace/add-ons/concepts/editor-auth-lifecycle#installed_versus_enabled)\nspecified in the test deployment. You can verify that the add-on functions as\nintended by interacting with its menu and UI elements.\n\n### Testing details\n\nThere are a number of things to keep in mind while testing Editor add-ons\nthis way:\n\n- [Installable triggers](/workspace/add-ons/concepts/editor-triggers#installable_triggers_in_add-ons) aren't supported when testing. Functionality that depends on installable triggers is not testable.\n- While running a test deployment that's set to test with the latest code, you can see changes saved to the add-on script by refreshing the test document.\n- The test document has a URL that you can share with editors of the original test document. This way, you can more easily collaborate with others while testing and developing.\n- If your add-on uses the [Properties service](/apps-script/reference/properties/properties-service), properties persist and remain available the next time the test deployment is run.\n- In addition, any test deployment that uses the same combination of add-on and test document has access to the same property information. For example, if you create two test deployments, the properties saved while running the first are available while running the second and vice versa, but only if the deployments use the same script and test document.\n- If you run a test deployment, you might be prompted for authorization if you have not run the script before. Be aware that authorizing a script while testing also authorizes the script outside of testing."]]