エディタのアドオンをテストする
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
アドオンが想定どおりに動作することを確認するため、公開前にアドオンを徹底的にテストする必要があります。Apps Script を使用すると、開発中のエディタ アドオンを特定の Google ドキュメント、スプレッドシート、フォーム、スライドのファイルでテストできます。次のような場合に使用できます。
- スタンドアロン スクリプトで記述されたアドオンが、シート、ドキュメント、プレゼンテーション、フォームに適用されたときに意図したとおりに機能することを確認します。
- アドオンのインストール フローが想定どおりに機能することを確認します。特に、さまざまな初期の承認ライフサイクルの状態(インストール済み、有効、またはその両方)で確認します。
- 特定のドキュメントとそのコンテンツに対してアドオンが意図したとおりに機能することを確認します。
- アドオンの現在のバージョンと以前のバージョンをテストして比較します。
テスト Deployment を作成する
テストのデプロイは、アドオンとテストドキュメントを組み合わせたものです。スクリプト バージョンを開発し、アドオンとしてテストする場合は、次の手順を行います。
- まだ作成していない場合は、スプレッドシート、ドキュメント、プレゼンテーション、またはフォームを作成してアドオンをテストします。
- アドオンを含むスクリプト プロジェクトを開きます。
- [Deploy](デプロイ)> [Test deployments](デプロイをテスト)をクリックします。
- [種類の選択] の横にある [デプロイタイプを有効にする] settings をクリックし、[エディタ アドオン] を選択します。
- [新しいテストを作成] または [テストを追加] をクリックします。
- コード バージョンを選択するか、[最新のコード] を選択します。
- [Config] セクションで、テストの初期認可状態を選択します。
- [テスト ドキュメント] で [ドキュメントが選択されていません] をクリックします。アドオンのテストに使用するスプレッドシート、ドキュメント、スライド、フォームのファイルを選択し、[挿入] をクリックします。
- [テストを保存] をクリックします。
保存したすべてのテストデプロイが [Test deployments] ダイアログに表示されます。これにより、後で同じテスト デプロイを再検討できます。
テストデプロイを実行する
保存したテストデプロイが 1 つ以上ある場合は、次の手順でいずれかを実行できます。
- アドオンを含むスクリプト プロジェクトを開きます。
- [Deploy](デプロイ)> [Test deployments](デプロイをテスト)をクリックします。
- [保存したテスト] で、実行する保存したテストのデプロイの横にあるラジオボタンを選択し、[実行] をクリックします。
テストドキュメントが新しいタブで開きます。アドオンは、テスト環境のデプロイで指定された認可状態にあります。メニューと UI 要素を操作して、アドオンが意図したとおりに機能することを確認できます。
テストの詳細
このようにエディタ アドオンをテストする際は、次の点に注意してください。
- テスト中はインストール可能なトリガーはサポートされていません。インストール可能なトリガーに依存する機能はテストできません。
- 最新のコードを使用してテストするように設定されたテストデプロイを実行しているときに、テストドキュメントを更新すると、アドオン スクリプトに保存された変更を確認できます。
- テストドキュメントには、元のテストドキュメントの編集者と共有できる URL があります。これにより、テストと開発中に他のユーザーとの共同作業がより簡単に行えます。
- アドオンがプロパティ サービスを使用している場合、プロパティは保持され、次回のテスト デプロイの実行時に引き続き使用できます。
- また、アドオンとテストドキュメントの組み合わせが同じテスト デプロイは、同じプロパティ情報にアクセスできます。たとえば、2 つのテスト デプロイメントを作成した場合、最初のデプロイメントの実行中に保存されたプロパティは、2 番目のデプロイメントの実行中に使用できます。その逆も同様です。ただし、デプロイメントで同じスクリプトとテストドキュメントを使用している場合に限られます。
- テスト デプロイを実行する場合、スクリプトを実行したことがない場合は、承認を求められることがあります。テスト中にスクリプトを承認すると、テスト以外のスクリプトも承認されます。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-12-22 UTC。
[null,null,["最終更新日 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."]]