Add-ons should be tested thoroughly prior to publishing to ensure they behave as intended. Apps Script lets you test Editor Add-ons in development on specific Google Docs Sheets, Forms, or Slides files. This can be used to:
- Verify that an add-on written in a standalone script functions as intended when applied to a sheet, doc, presentation, or form.
- Verify that the add-on installation flow works as intended, particularly for different initial authorization lifecycle states (installed, enabled, or both).
- Verify that the add-on functions as intended when acting on a particular document and its contents.
- Test and compare the current and previous versions of the add-on.
Create a test deployment
A test deployment is the combination of an add-on and a test document. Once you have a script version developed and would like to test it as an add-on, follow these steps:
- If you don’t have one already, create a spreadsheet, document, presentation, or form to test the add-on with.
- Open the script project containing your add-on.
- Click Deploy > Test deployments.
- Next to Select type, click Enable deployment types and select Editor Add-on.
- Click Create new test or Add test.
- Choose a code version or select Latest Code.
- In the Config section, select the initial authorization state for the test.
- 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.
- Click Save test.
All saved test deployments appear in the Test deployments dialog. This lets you revisit the same test deployment later on.
Run a test deployment
If you have one or more saved test deployments, you can run one of them by following these steps:
- Open the script project containing your add-on.
- Click Deploy > Test deployments.
- Under Saved Tests, select the radio button next to the saved test deployment you want to run and click Execute.
The test document opens in a new tab. The add-on is in the authorization state specified in the test deployment. You can verify that the add-on functions as intended by interacting with its menu and UI elements.
Testing details
There are a number of things to keep in mind while testing Editor Add-ons this way:
- Installable triggers aren't supported when testing. Functionality that depends on installable triggers is not testable.
- 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.
- 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.
- If your add-on uses the Properties service, properties persist and remain available the next time the test deployment is run.
- 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.
- 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.