简体   繁体   English

使用Realm和XCTest进行测试-权限被拒绝?

[英]Testing with Realm and XCTest — Permission Denied?

Whenever I try to read or write from the Realm within an XCTest, I'm getting this permission denied error: "RLMException", "open() failed: Permission denied" . 每当我尝试在XCTest中从领域读取或写入内容时,都会收到此权限被拒绝的错误: "RLMException", "open() failed: Permission denied"

Even after making sure that the default Realm is set to a different path ( RLMRealm.setDefaultRealmPath("TestRealm") ) before any test is run, the problem still persists. 即使在运行任何测试之前确保将默认Realm设置为其他路径( RLMRealm.setDefaultRealmPath("TestRealm") ),问题仍然存在。

I'd like to avoid losing simplicity by passing through a Realm with every model function to accommodate testing them. 我想避免通过传递带有每个模型函数的Realm来适应测试的方式而失去简单性。 The docs state it's possible, but I can't seem to get it working. 文档指出这是可能的,但我似乎无法使其正常运行。

RLMRealm.setDefaultRealmPath(_:) is expecting an absolute path to the Realm file, so "TestRealm" is not a suitable path. RLMRealm.setDefaultRealmPath(_:)期望使用Realm文件的绝对路径,因此“ TestRealm”不是合适的路径。 Changing that to a path that the process has write access to should fix your issue. 将其更改为该进程具有写权限的路径应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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