简体   繁体   中英

Testing Google Sheet Addon Triggers

I working on a Google Sheet Add-on. When testing the addon [from the legacy editor Run --> Test as add-on] and selecting "Test with latest code" sometime it does not run the latest code (I know this because I've made changes to the code and error messages are pointing old line numbers).

Saving a version number and specifying that in the test screen doesn't seem to help either.

Turns out the problems was that parts of my "Test" Add-on was running from my production deploy add-on NOT my test code. This was super confusing and took a long time to understand.

I knew that " Installable Triggers " (aka onOpen) cannot be installed or tested via editor (you will get error message when trying to install them) but thought " Simple Triggers " did work since the onInstall work and runs when testing an Add-on. However this is not true, other simpleTriggers - such as onEdit - will not run in test mode.

My test spreadsheet had magically enabled the deployed Add On [you should have to manually enabled addon to be available for each spreadsheet] so onEdit event were running creating log messages right next to development code messages - super confusing!

To avoid this problem, I completely uninstall the Production Addon from my account. Not ideal since I'll have to re-install it to test production deploys.

Also I had to rewrite my trigger code so it could be tested manually via menu bar (since the "even object" isn't available) otherwise you must deploy your code every time you want to add a debug statement.

I hope this save someone some head banging!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM