我可以在 Google Apps 脚本中测试 DocumentProperties 吗?

Can I test DocumentProperties in Google Apps Scripts?

是否可以测试使用 DocumentProperties 的 Google Apps 脚本? testing documentation 似乎表明这是可能的:

If your add-on uses the Properties service, properties will persist and remain available the next time the test configuration is run.

但是,当我尝试使用 DocumentProperties 时,出现以下错误:

Google Apps Script: You do not have permission to call getDocumentProperties

这是我正在尝试的代码:

function appFolderExists(){
    PropertiesService.getDocumentProperties().getProperties();
    return true;
}

function onOpen() {
    FormApp.getUi().createMenu('My Addon')
        .addItem('My Addon', 'showSidebar')
        .addToUi();
    if(!appFolderExists()){
        createAppFolder();
    }
}

我的插件当前部署为测试(用于表单)。它已安装但未启用。

我想在 appFolderExists 中添加更多逻辑,但由于看不到访问 DocumentProperties,我一直卡住了。我做错了什么或者这只是测试插件的不便限制?

此问题是由于测试加载项已安装但未启用所致。因此 运行s authmode.None 中的代码,在此模式下您无法访问文档 Properties

解决方案:
1) 运行 安装和启用的测试
2)确定authmode和运行的相关代码:

function open(e){

if (e.authMode == ScriptApp.AuthMode.NONE){
// Code that does not access document properties
} else {
var prop = PropertiesService.getDocumentProperties().getProperties();
// Some code that uses document properties
}
}